SKIP

SKIP (and its synonym OFFSET) defines from which row to start including the rows in the output.

By using SKIP, the result set will get trimmed from the top.

Neo4j does not guarantee the results generated by SKIP/OFFSET. The only clause that guarantees a specific row order is ORDER BY.

SKIP accepts any expression that evaluates to a positive INTEGER and does not refer to nodes or relationships.

Example graph

The following graph is used for the examples below:

graph skip clause

To recreate it, run the following query against an empty Neo4j database:

CREATE
  (andy: Person {name: 'Andy'}),
  (bernard: Person {name: 'Bernard'}),
  (charlotte: Person {name: 'Charlotte'}),
  (david: Person {name: 'David'}),
  (erika: Person {name: 'Erika'}),
  (andy)-[:KNOWS]->(bernard),
  (andy)-[:KNOWS]->(charlotte),
  (andy)-[:KNOWS]->(david),
  (andy)-[:KNOWS]->(erika)

Examples

Example 1. Skip the first three rows

The following query returns a subset of the result, starting from the fourth result.

Query
MATCH (n)
RETURN n.name
ORDER BY n.name
SKIP 3
Table 1. Result
n.name

"David"

"Erika"

Rows: 2

Example 2. Return the middle two rows

The following query returns the middle two rows, with SKIP skipping the first and LIMIT removing the final two.

Query
MATCH (n)
RETURN n.name
ORDER BY n.name
SKIP 1
LIMIT 2
Table 2. Result
n.name

"Bernard"

"Charlotte"

Rows: 2

Example 3. Using an expression with SKIP to return a subset of the rows

SKIP accepts any expression that evaluates to a positive INTEGER, as long as it can be statically calculated (i.e. calculated before the query is run).

This query skips the first row and then randomly skips an additional 0, 1, or 2 rows, resulting in skipping a total of 1, 2, or 3 rows before returning the remaining names.

Query
MATCH (n)
RETURN n.name
ORDER BY n.name
SKIP 1 + toInteger(3 * rand())
Table 3. Result
n.name

"Bernard"

"Charlotte"

"David"

"Erika"

Rows: 4

Using SKIP as a standalone clause

SKIP can be used as a standalone clause, or in conjunction with ORDER BY or LIMIT.

Standalone use of SKIP
MATCH (n)
SKIP 2
RETURN collect(n.name) AS names
Table 4. Result
names

["Charlotte", "David", "Erika"]

Rows: 1

The following query orders all nodes by name, skips the two first rows and limits the results to two rows. It then collects the results in a list.

SKIP used in conjunction with ORDER BY and LIMIT
MATCH (n)
ORDER BY n.name
SKIP 2
LIMIT 2
RETURN collect(n.name) AS names
Table 5. Result
names

["Charlotte", "David"]

Rows: 1

OFFSET as a synonym to SKIP

OFFSET was introduced as part of Cypher®'s GQL conformance and can be used as a synonym to SKIP.

Query
MATCH (n)
ORDER BY n.name
OFFSET 2
LIMIT 2
RETURN collect(n.name) AS names
Table 6. Result
names

["Charlotte", "David"]

Rows: 1