Skip
SKIP
controls the number of tuples to skip from the start of the queryResult. It is often used within in an ORDER BY
clause to skip the top k tuples from the query result.
Note: SKIP accepts any expression that can be evaluated to an integer.
We will use the example database for demonstration, whose schema and data import commands are given here.
For example, the following query skips the youngest 2 users and returns the rest of the users’ ages. Query:
MATCH (u:User)RETURN u.nameORDER BY u.ageSKIP 2;
Result:
┌─────────┐│ u.name ││ STRING │├─────────┤│ Karissa ││ Zhang │└─────────┘
If you omit the ORDER BY
, you would skip some k tuples in a SKIP
k query
but you have no guarantee about which ones will be skipped.
The number of rows to skip can either be:
- A parameter expression when used with prepared statement:
Prepare:
auto prepared = conn->prepare("MATCH (u:User) RETURN u.name skip $sp")
Execution:
The number of rows to skip can be given at the time of execution.
conn->execute(prepared.get(), std::make_pair(std::string{"sp"}, 2))
Result:
┌────────┐│ u.name ││ STRING │├────────┤│ Zhang ││ Noura │└────────┘
- A literal expression which can be evaluated at compile time.
MATCH (u:User)RETURN u.nameskip 2+1
Result:
┌────────┐│ u.name ││ STRING │├────────┤│ Noura │└────────┘