0Pricing
Neo4j Graph Database Fundamentals · Lesson

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

  1. Filtering and Ordering Results
  2. Aggregation and Projections
  3. Updating and Deleting Graph Data
  4. Combining Queries with WITH and UNION
← Back to Neo4j Graph Database Fundamentals