Reading Data

MATCH

The MATCH clause finds patterns in the graph. Nodes are wrapped in parentheses, relationships in square brackets.

-- Match all nodes with a label
MATCH (n:Person) RETURN n

-- Match with inline property filter
MATCH (n:Person {name: "Alice"}) RETURN n

-- Match relationship patterns
MATCH (a:Person)-[r:FRIEND]->(b:Person)
RETURN a.name, b.name, r.since

-- Multiple patterns (implicit join on shared variables)
MATCH (a:Person)-[:WORKS_AT]->(c:Company),
      (a)-[:HAS_SKILL]->(s:Skill)
RETURN a.name, c.name, s.name

-- Undirected relationships
MATCH (a:Person)-[:FRIEND]-(b:Person)
RETURN a.name, b.name

OPTIONAL MATCH

Like MATCH, but returns null for unmatched parts instead of filtering out the row.

MATCH (p:Person)
OPTIONAL MATCH (p)-[:MANAGES]->(project:Project)
RETURN p.name, project.name

WITH

Chains query stages. Acts as a projection barrier - only variables listed in WITH are visible downstream.

MATCH (p:Person)-[:FRIEND]->(f)
WITH p, count(f) AS friendCount
WHERE friendCount > 3
RETURN p.name, friendCount
ORDER BY friendCount DESC

UNWIND

Expands a list into individual rows.

UNWIND [1, 2, 3] AS x RETURN x

-- Combine with MATCH
WITH ["Alice", "Bob", "Charlie"] AS names
UNWIND names AS name
MATCH (p:Person {name: name})
RETURN p

UNION

-- Deduplicated union
MATCH (n:Person) RETURN n.name AS name
UNION
MATCH (n:Company) RETURN n.name AS name

-- Keep duplicates
MATCH (n:Person) RETURN n.name AS name
UNION ALL
MATCH (n:Company) RETURN n.name AS name

ORDER BY / SKIP / LIMIT

MATCH (n:Person)
RETURN n.name, n.age
ORDER BY n.age DESC, n.name ASC
SKIP 10
LIMIT 25