14.1. Finding basic patterns

SQL starts with the result you want — we SELECT what we want and then declare how to source it. In Cypher, instead you find nodes and relationships that are connected in a certain way by describing them as a graph pattern in a MATCH clause. The query may then execute from any found instances of the pattern.

From a SQL point of view, the identifiers in a pattern are like table names that point to a set of nodes or relationships. The set can be listed literally, come via parameters, or as I show in the following example, be defined by an index look-up.

So in fact rather than being SELECT-like, the MATCH clause is somewhere between the FROM and the WHERE clause in SQL.

SQL Query 

FROM "Person"
WHERE name = 'Anakin'

1 rows





Cypher Query 

MATCH (person:Person { name: 'Anakin' })
RETURN person

1 row


Cypher allows multiple starting points. This should not be strange from a SQL perspective — every table in the FROM clause is another starting point.