Course contentsShow
← System Design
Lesson 461 of 1,91913. NoSQL: Graph DatabasesFree lesson

Cypher Query Language Fundamentals

Introduction to Cypher: pattern matching syntax, ASCII-art style queries, and basic MATCH and RETURN statements.

Cypher Query Language Fundamentals

What you'll learn: How to read and write basic Cypher queries using its intuitive ASCII-art pattern matching syntax.

The ASCII-Art Approach

Cypher is Neo4j's query language designed to feel natural when working with graphs. Unlike SQL's table-focused syntax, Cypher uses ASCII-art to visually represent graph patterns. Nodes are written in parentheses (n), and relationships use arrows --> or <--. This mirrors how you'd sketch a graph on a whiteboard.

Think of it like giving directions: "Find all users who follow artists" becomes a visual pattern you can almost draw with keyboard characters.

Basic Pattern Matching

The core Cypher statement is MATCH, which searches for patterns in your graph. You describe what structure you're looking for, and Cypher finds all instances that match.

MATCH (user:Person)-[:FOLLOWS]->(artist:Person)
RETURN user.name, artist.name

Breaking this down:

  • (user:Person) — A node labeled "Person", assigned to variable user
  • -[:FOLLOWS]-> — A directed relationship of type "FOLLOWS"
  • (artist:Person) — Another Person node, assigned to variable artist
  • RETURN — Specifies which data to output

The arrow direction matters: -> means "follows," while <- would mean "is followed by."

Simple Queries

Find a specific node:

MATCH (p:Person {name: "Alice"})
RETURN p

Find all nodes of a type:

MATCH (p:Person)
RETURN p.name, p.age

The pattern matching reads left-to-right like a sentence, making queries intuitive even for beginners.

Key Takeaway: Cypher uses ASCII-art patterns with MATCH to find graph structures and RETURN to extract data, making graph queries visual and readable—nodes in (), relationships in -->.