OFFSET
Skip results for pagination. OFFSET works with LIMIT to implement page-based navigation through large result sets.
Understanding OFFSET
The OFFSET clause skips a specified number of results before returning data. Combined with LIMIT, it enables pagination - retrieving results in manageable chunks or "pages."
Key entities used in examples:
wdt:P31 (instance of) links an item to its type, while
wd:Q515 (city) and wd:Q6256 (country) are common type values.
Other properties include wdt:P1082 (population), wdt:P2044 (elevation),
wdt:P571 (inception), and wdt:P106 (occupation). Example values include
wd:Q5 (human) and wd:Q36180 (writer).
| Syntax | Description | Result |
|---|---|---|
LIMIT 10 OFFSET 0 |
Page 1 (first 10) | Results 1-10 |
LIMIT 10 OFFSET 10 |
Page 2 | Results 11-20 |
LIMIT 10 OFFSET 20 |
Page 3 | Results 21-30 |
LIMIT n OFFSET (p-1)*n |
Page p with n items | General formula |
Pagination Examples
SELECT ?country ?countryLabel
WHERE {
?country wdt:P31 wd:Q6256 .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
}
ORDER BY ?countryLabel
LIMIT 10
OFFSET 0
The pattern ?country wdt:P31 wd:Q6256 selects entities that are countries. Page 1 shows the
first 10 countries alphabetically because LIMIT 10 is combined with OFFSET 0.
SELECT ?country ?countryLabel
WHERE {
?country wdt:P31 wd:Q6256 .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
}
ORDER BY ?countryLabel
LIMIT 10
OFFSET 10
Page 2 skips the first 10 results with OFFSET 10 and returns the next 10.
SELECT ?country ?countryLabel
WHERE {
?country wdt:P31 wd:Q6256 .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
}
ORDER BY ?countryLabel
LIMIT 10
OFFSET 40
Page 5 uses OFFSET 40 to skip 40 rows, then LIMIT 10 to show rows 41-50.
Pagination with Rankings
OFFSET is especially useful when combined with ORDER BY to create paginated rankings - showing the 11th-20th most populous cities, for example.
SELECT ?city ?cityLabel ?population
WHERE {
?city wdt:P31 wd:Q515 ;
wdt:P1082 ?population .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
}
ORDER BY DESC(?population)
LIMIT 10
OFFSET 10
This query orders cities by population (descending) and uses OFFSET 10 with LIMIT 10
to return ranks 11-20.
SELECT ?mountain ?mountainLabel ?elevation
WHERE {
?mountain wdt:P31 wd:Q8502 ;
wdt:P2044 ?elevation .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
}
ORDER BY DESC(?elevation)
LIMIT 10
OFFSET 20
Mountains are sorted by elevation (descending). OFFSET 20 skips the top 20 to show ranks 21-30.
Skip-Then-Sample Pattern
OFFSET can be used creatively to skip common results and find less-obvious examples in the data.
SELECT ?author ?authorLabel ?works
WHERE {
?author wdt:P31 wd:Q5 ;
wdt:P106 wd:Q36180 .
{
SELECT ?author (COUNT(?work) AS ?works)
WHERE {
?work wdt:P50 ?author .
}
GROUP BY ?author
}
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
}
ORDER BY DESC(?works)
LIMIT 10
OFFSET 100
The subquery counts works per author, then ORDER BY DESC(?works) ranks them. OFFSET 100
skips the most prolific authors to sample the next 10.
SELECT ?uni ?uniLabel ?founded
WHERE {
?uni wdt:P31 wd:Q3918 ;
wdt:P571 ?founded .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
}
ORDER BY ?founded
LIMIT 20
OFFSET 50
Universities are ordered by founding date, so OFFSET 50 skips the oldest 50 before returning 20.
Important Considerations
OFFSET requires ORDER BY for consistent results. Without ordering, the same OFFSET may return different results each time. Also note that high OFFSET values can be slow - the database still processes all skipped rows.
# Always use ORDER BY with OFFSET for consistent results
SELECT ?item ?itemLabel
WHERE {
?item wdt:P31 wd:Q6256 .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
}
ORDER BY ?item # Order by URI for stable results
LIMIT 10
OFFSET 30
ORDER BY ?item gives a stable, repeatable order so the same OFFSET returns
consistent pages.