Returning and Shaping Results with RETURN
Master the Cypher RETURN clause to project, alias, and shape the output of your graph queries.
Returning and Shaping Results with RETURN is a free Neo4j Graph Database Fundamentals lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Neo4j Graph Database Fundamentals learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What RETURN Does
Every read query that produces output ends with a RETURN clause. It defines exactly which values come back to you.
Think of RETURN as the projection step of your query.
MATCH (p:Person)
RETURN p;Returning Specific Properties
Instead of whole nodes, you can return individual properties using dot notation. This keeps results lean.
MATCH (p:Person)
RETURN p.name, p.age;Aliasing with AS
Use AS to rename a returned column. This makes output clearer and is essential when returning computed values.
MATCH (p:Person)
RETURN p.name AS personName, p.age AS years;Returning Relationships
You can return the relationship variable too, not just nodes. This is useful when you need relationship properties.
MATCH (a:Person)-[r:FRIEND]->(b:Person)
RETURN a.name, type(r), b.name;Computed Expressions
RETURN can contain expressions: arithmetic, string functions, and more.
MATCH (p:Person)
RETURN p.name, p.age * 12 AS ageInMonths;DISTINCT Results
Add DISTINCT to remove duplicate rows from the output, just like in SQL.
MATCH (p:Person)-[:LIVES_IN]->(c:City)
RETURN DISTINCT c.name;Returning Literals
You can return constant values and labels for readability or debugging.
RETURN 'Hello Cypher' AS greeting, 1 + 1 AS sum;Returning Multiple Patterns
A single RETURN can combine values from many matched variables, building rich rows.
MATCH (u:User)-[:PLACED]->(o:Order)
RETURN u.name, o.id, o.total;Working with Functions
Useful functions in RETURN include id(), labels(), type(), and toUpper().
MATCH (p:Person)
RETURN labels(p) AS nodeLabels, toUpper(p.name) AS upperName;Returning a Whole Path
Capture a path in a variable and return it to inspect the full chain of nodes and relationships.
MATCH path = (a:Person {name: 'Alice'})-[:FRIEND*1..2]->(b)
RETURN path;Keeping Output Clean
Best practice: return only what you need. Returning entire nodes when you only use one property wastes bandwidth and clutters results.
Quick Check
Test your RETURN knowledge.
Recap
You learned to shape query output with RETURN:
- Return whole nodes or specific properties
- Alias columns with AS
- Use DISTINCT to remove duplicates
- Include expressions and functions
- Return paths and relationships when needed
Frequently asked questions
Is the “Returning and Shaping Results with RETURN” lesson free?
Yes — the full text of “Returning and Shaping Results with RETURN” is free to read here on the web, and the Neo4j Graph Database Fundamentals course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Neo4j Graph Database Fundamentals course, upgrade to CoddyKit PRO.
What will I learn in “Returning and Shaping Results with RETURN”?
Master the Cypher RETURN clause to project, alias, and shape the output of your graph queries. You practise Neo4j Graph Database Fundamentals with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Neo4j Graph Database Fundamentals?
No prior experience is required. Neo4j Graph Database Fundamentals on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Returning and Shaping Results with RETURN” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Neo4j Graph Database Fundamentals lesson?
Yes. Every Neo4j Graph Database Fundamentals lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Nodes, Relationships, and Properties
- Creating Data with Cypher CREATE
- Matching Patterns with Cypher MATCH
- Returning and Shaping Results with RETURN