3.3. Clauses

Read Clauses

These comprise clauses that read data from the database.

The flow of data within a Cypher query is an unordered sequence of maps with key-value pairs — a set of possible bindings between the variables in the query and values derived from the database. This set is refined and augmented by subsequent parts of the query.

Clause Description

MATCH

Specify the patterns to search for in the database.

OPTIONAL MATCH

Specify the patterns to search for in the database while using nulls for missing parts of the pattern.

WHERE

Adds constraints to the patterns in a MATCH or OPTIONAL MATCH clause or filter the results of a WITH clause.

START

Find starting points through legacy indexes.

Aggregation

Aggregation functions including count(), sum(), avg(), max(), min(), collect() and others. Includes DISTINCT.

LOAD CSV

Use when importing data from CSV files.

Write Clauses

These comprise clauses that write the data to the database.

Clause Description

CREATE

Create nodes and relationships.

MERGE

Ensures that a pattern exists in the graph. Either the pattern already exists, or it needs to be created.

SET

Update labels on nodes and properties on nodes and relationships.

DELETE

Delete graph elements — nodes, relationships or paths.

REMOVE

Remove properties and labels from nodes and relationships.

FOREACH

Update data within a list, whether components of a path, or the result of aggregation.

CREATE UNIQUE

A mixture of MATCH and CREATE, matching what it can, and creating what is missing.

Importing CSV files with Cypher

How to import data from CSV files using LOAD CSV.

PERIODIC COMMIT

How and when to use PERIODIC COMMIT

General Clauses

These comprise general clauses that work in conjunction with other clauses.

Clause Description

RETURN

Defines what to include in the query result set.

ORDER BY

A sub-clause following RETURN or WITH, specifying that the output should be sorted in particular way.

LIMIT

Constrains the number of rows in the output.

SKIP

Defines from which row to start including the rows in the output.

WITH

Allows query parts to be chained together, piping the results from one to be used as starting points or criteria in the next.

UNWIND

Expands a list into a sequence of rows.

UNION

Combines the result of multiple queries.

CALL

Invoke a procedure deployed in the database.