Combining Queries with WITH and UNION
Learn to chain query stages using WITH and merge result sets using UNION for advanced Cypher querying.
Why Chain Query Stages
Complex questions often need several steps: filter, aggregate, then filter again. Cypher uses WITH to pass results from one stage to the next.
Introducing WITH
WITH works like RETURN but feeds its output into the next part of the query instead of ending it.
MATCH (p:Person)-[:FRIEND]->(f)
WITH p, count(f) AS friendCount
WHERE friendCount > 3
RETURN p.name, friendCount;All lessons in this course
- Filtering and Ordering Results
- Aggregation and Projections
- Updating and Deleting Graph Data
- Combining Queries with WITH and UNION