3.3.9. SKIP

SKIP defines from which row to start including the rows in the output.

3.3.9.1. Introduction

By using SKIP, the result set will get trimmed from the top. Please note that no guarantees are made on the order of the result unless the query specifies the ORDER BY clause. SKIP accepts any expression that evaluates to a positive integer — however the expression cannot refer to nodes or relationships.

Figure 3.15. Graph
alt

3.3.9.2. Skip first three rows

To return a subset of the result, starting from the fourth result, use the following syntax:

Query. 

MATCH (n)
RETURN n.name
ORDER BY n.name
SKIP 3

The first three nodes are skipped, and only the last two are returned in the result.

Table 3.101. Result
n.name

2 rows

"D"

"E"

Try this query live.  CREATE (a {name: 'A'}), (b {name: 'B'}), (c {name: 'C'}), (d {name: 'D'}), (e {name: 'E'}), (a)-[:KNOWS]->(b), (a)-[:KNOWS]->(c), (a)-[:KNOWS]->(d), (a)-[:KNOWS]->(e) MATCH (n) RETURN n.name ORDER BY n.name SKIP 3

3.3.9.3. Return middle two rows

To return a subset of the result, starting from somewhere in the middle, use this syntax:

Query. 

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

Two nodes from the middle are returned.

Table 3.102. Result
n.name

2 rows

"B"

"C"

Try this query live.  CREATE (a {name: 'A'}), (b {name: 'B'}), (c {name: 'C'}), (d {name: 'D'}), (e {name: 'E'}), (a)-[:KNOWS]->(b), (a)-[:KNOWS]->(c), (a)-[:KNOWS]->(d), (a)-[:KNOWS]->(e) MATCH (n) RETURN n.name ORDER BY n.name SKIP 1 LIMIT 2

3.3.9.4. 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 is not referring to any external variables:

Query. 

MATCH (n)
RETURN n.name
ORDER BY n.name
SKIP toInt(3*rand())+ 1

The first three nodes are skipped, and only the last two are returned in the result.

Table 3.103. Result
n.name

4 rows

"B"

"C"

"D"

"E"

Try this query live.  CREATE (a {name: 'A'}), (b {name: 'B'}), (c {name: 'C'}), (d {name: 'D'}), (e {name: 'E'}), (a)-[:KNOWS]->(b), (a)-[:KNOWS]->(c), (a)-[:KNOWS]->(d), (a)-[:KNOWS]->(e) MATCH (n) RETURN n.name ORDER BY n.name SKIP toInt(3*rand()) + 1