Skip
SKIP
controls the number of tuples to skip from the start of the query result. It is often used within 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 2 youngest users and returns the rest of the usersβ ages. Query:
MATCH (u:User)RETURN u.nameORDER BY u.ageSKIP 2;
ββββββββββββ u.name ββ STRING ββββββββββββ€β Karissa ββ Zhang ββββββββββββ
If you omit the ORDER BY
, you would skip some k tuples in a SKIP
k query
but there is 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))
βββββββββββ u.name ββ STRING βββββββββββ€β Zhang ββ Noura βββββββββββ
- A literal expression which can be evaluated at compile time.
MATCH (u:User)RETURN u.nameskip 2+1
βββββββββββ u.name ββ STRING βββββββββββ€β Noura βββββββββββ