Neo4j Query Language - Cypher

Neo4j has its own query language called Cypher. Cypher uses a similar syntax to SQL (Structured Query Language).


Here's an example of a Cypher statement:

This Cypher statement returns a "Person" node where the name property is "Homer Flinstone".

If this was SQL querying a relational database, it might look more like this:

However, remember, Neo4j doesn't store its data in tables like the relational database model. It's all in nodes and relationships. So the Cypher query above is querying nodes, their labels, and their properties. The SQL example on the other hand, is querying tables, rows, and columns.

SQL was designed to be used with relational database management systems (DBMS). Neo4j is a NoSQL DBMS, in that it doesn't use the relational model and it doesn't use SQL.

Cypher was designed specifically for working with the Neo4j data model, which is all about nodes and their relationships with each other.

ASCII-Art Syntax

Cypher uses ASCII-Art to represent patterns. This is a handy thing to remember when first learning the language. If you forget how to write something, just visualise how the graph will look and it should help.

The main things to remember:

Defining the Data

Here are some more points to remember when working with Cypher:

So looking at the above example again:

We can see that: