MATCH finds structure; RETURN shapes the table
Cypher is a declarative pattern language. You describe the shape of graph data you care about with
MATCH, optionally filter with WHERE
(next lesson), then RETURN the columns of your result table.
Unlike imperative code that walks adjacency lists by hand, you state the pattern and let the engine
choose an execution plan.
A minimal read looks like: match something, return something. Patterns live inside parentheses for nodes
and square brackets for relationships. Directional arrows show which way the relationship is stored.
When you write (p:Person)-[:ACTED_IN]->(m:Movie), you ask Neo4j for every
pair where a Person node has an outgoing ACTED_IN relationship into a Movie node.
When to use MATCH: any time you need to read existing graph structure—dashboards, APIs, analytics, exploration. MATCH does not modify data. Empty results mean no subgraph matched your pattern; they are not errors. That distinction matters when you debug: check labels, types, direction, and whether the dataset was loaded.
RETURN produces the client-visible table. You can return whole nodes
(RETURN p), properties (p.name),
expressions, and aliases with AS. Prefer projecting the columns you
need; returning entire large node objects is harder to read and can be expensive over the wire in
applications. ORDER BY and LIMIT are your friends while learning: they stabilize examples and protect
the UI from thousand-row floods.
Why patterns beat ad-hoc client traversal: application developers sometimes fetch a node by ID, then issue more queries for neighbors in a loop. That stacks latency and is easy to get wrong under concurrency. A single Cypher MATCH that describes the full subgraph you need lets the database planner use indexes and expand relationships efficiently. As patterns grow—co-actors, director–cast graphs, multi-film careers—you still express them as ASCII art of the graph rather than nested client loops.
MATCH (p:Person)-[r:ACTED_IN]->(m:Movie)
// identifiers p, r, m are in scope for RETURN
RETURN p.name AS actor, m.title AS film, type(r) AS relType
LIMIT 5