Reading clauses
| Clause | Query | Description |
|---|---|---|
| MATCH | MATCH (n) RETURN n | Specify the patterns to search for in the database. |
| OPTIONAL MATCH | MATCH (node:label {properties. . . . . . . . . . . . . .}) OPTIONAL MATCH (node)-->(x) RETURN x | Specify the patterns to search for in the database while using nulls for missing parts of the pattern. |
Projecting clauses
| Clause | Query | Description |
|---|---|---|
| RETURN … [AS] | MATCH (n { name: 'A' }) RETURN n | Defines what to include in the query result set. |
| WITH … [AS] | MATCH (n) WITH n ORDER BY n.property RETURN collect(n.property) | Allows query parts to be chained together, piping the results from one to be used as starting points or criteria in the next. |
| UNWIND … [AS] | UNWIND [a, b, c, d] AS x RETURN x | Expands a list into a sequence of rows. |
Reading sub-clauses
| Sub-clause | Query | Description |
|---|---|---|
| WHERE | MATCH (label) WHERE label.country = "property" RETURN label | Adds constraints to the patterns in a MATCH or OPTIONAL MATCH clause or filters the results of a WITH clause. |
| ORDER BY [ASC[ENDING] | DESC[ENDING]] | MATCH (n) RETURN n.property1, n.property2 . . . . . . . . | A sub-clause following RETURN or WITH, specifying that the output should be sorted in either ascending (the default) or descending order. |
| SKIP | MATCH (n) RETURN n.name, n.runs ORDER BY n.runs DESC SKIP numberofrows | Defines from which row to start including the rows in the output. |
| LIMIT | MATCH (n) RETURN n ORDER BY n.name | Constrains the number of rows in the output. |
Reading hints
| Hint | Description |
|---|---|
| USING INDEX | Index hints are used to specify which index, if any, the planner should use as a starting point. |
| USING INDEX SEEK | Index seek hint instructs the planner to use an index seek for this clause. |
| USING SCAN | Scan hints are used to force the planner to do a label scan (followed by a filtering operation) instead of using an index. |
| USING JOIN | Join hints are used to enforce a join operation at specified points. |
Writing clauses
| Clause | Query | Description |
|---|---|---|
| CREATE | CREATE (node_name);or CREATE (node1),(node2) | Create nodes and relationships. |
| DELETE | MATCH (n) DELETE n | Delete nodes, relationships or paths. Any node to be deleted must also have all associated relationships explicitly deleted. |
| DETACH DELETE | MATCH (n) DETACH DELETE n | Delete a node or set of nodes. All associated relationships will automatically be deleted. |
| SET | MATCH (node:label{properties . . . . . . . . . . . . . . }) | Update labels on nodes and properties on nodes and relationships. |
| REMOVE | MATCH (node:label{properties . . . . . . . }) | Remove properties and labels from nodes and relationships. |
| FOREACH | MATCH p = (start node)-[*]->(end node) | Update data within a list, whether components of a path, or the result of aggregation. |
Reading/Writing clauses
| Clause | Query | Description |
|---|---|---|
| MERGE | MERGE (node: label {properties . . . . . . . }) | Ensures that a pattern exists in the graph. Either the pattern already exists, or it needs to be created. |
| — ON CREATE | MERGE (node:label {properties . . . . . . . . . . .}) | Used in conjunction with MERGE, this write sub-clause specifies the actions to take if the pattern needs to be created. |
| — ON MATCH | MERGE (node:label {properties . . . . . . . . . . .}) | Used in conjunction with MERGE, this write sub-clause specifies the actions to take if the pattern already exists. |
| CALL […YIELD] | CALL dbms.procedures() YIELD name, signature, description as text WHERE name STARTS WITH 'db.' RETURN * ORDER BY name ASC | Invokes a procedure deployed in the database and return any results. |
Set operations
| Clause | Query | Description |
|---|---|---|
| UNION | <MATCH Command1> <MATCH Command2> | Combines the result of multiple queries into a single result set. Duplicates are removed. |
| UNION ALL | <MATCH Command1> UNION ALL | Combines the result of multiple queries into a single result set. Duplicates are retained. |
Subquery clauses
| Clause | Description |
|---|---|
| CALL { … } | Evaluates a subquery, typically used for post-union processing or aggregations. |
Multiple graphs
| Clause | Query | Description |
|---|---|---|
| USE | USE <graph> <other clauses> | Determines which graph a query, or query part, is executed against. |