Querying Graphs with Cypher

Graph query languages let you ask questions by drawing the shape of the answer. Today you'll learn Cypher's declarative, pattern-matching approach: how to describe nodes and relationships as ASCII-art patterns, filter with WHERE, traverse multiple hops, aggregate results, and write data with CREATE and MERGE — and why this reads so differently from SQL joins.

Day 3 Progress0%

The Property-Graph Query Model

Cypher is the declarative query language for property graphs, originally created for Neo4j and now standardized as the basis of GQL (ISO/IEC 39075). Instead of describing how to fetch data step by step, you describe the shape of the pattern you want and let the engine find every place it occurs.

A Tiny Example Graph

We'll use this small social-and-work graph throughout the lesson:

  • People: Alice, Bob, Carol, Dave
  • Companies: Acme, Globex
  • Alice and Bob WORKS_AT Acme; Carol WORKS_AT Globex
  • Alice KNOWS Bob; Bob KNOWS Carol; Carol KNOWS Dave
  • Alice CREATED the Widget product; Acme PRODUCES Widget

Declarative, Not Procedural

A relational query says join these tables on these keys. A Cypher query instead draws the relationship you're after:

MATCH (a:Person)-[:WORKS_AT]->(c:Company)
RETURN a.name, c.name

You never wrote a join condition. The arrow is the join, and the engine resolves it by following stored relationships.

Labels, Types, and Properties

  • A node label such as :Person groups nodes of the same kind.
  • A relationship type such as :WORKS_AT names the kind of edge.
  • Both nodes and relationships hold properties{name: "Alice"}, {since: 2021}.

Cypher is case-sensitive for labels, types, and property keys, and keywords are conventionally written in uppercase.

Key Takeaways
  • Cypher is declarative: you describe the pattern, not the join algorithm
  • Nodes carry labels (:Person) and relationships carry types (:WORKS_AT); both hold properties
  • Cypher is the basis of the ISO GQL standard for property-graph queries

AI Learning Assistant

Powered by advanced LLM

Get personalized help with concepts, code examples, and explanations tailored to your learning pace.

Course Stats

Estimated Time
60 min
Lessons
5 sections