0
0
PostgreSQLquery~20 mins

LIMIT and OFFSET pagination in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Pagination Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What rows are returned by this query?
Consider a table employees with 10 rows numbered 1 to 10 by id. What rows does this query return?

SELECT * FROM employees ORDER BY id ASC LIMIT 3 OFFSET 4;
PostgreSQL
SELECT * FROM employees ORDER BY id ASC LIMIT 3 OFFSET 4;
ARows with id 5, 6, and 7
BRows with id 1, 2, and 3
CRows with id 4, 5, and 6
DRows with id 6, 7, and 8
Attempts:
2 left
💡 Hint
OFFSET skips the first N rows, LIMIT picks how many rows after that.
🧠 Conceptual
intermediate
1:30remaining
Why use OFFSET with LIMIT for pagination?
Which is the best reason to use LIMIT with OFFSET in a query for pagination?
ATo delete rows after a certain position
BTo update rows in batches
CTo skip a set number of rows and then return a fixed number of rows for a page
DTo group rows by a column
Attempts:
2 left
💡 Hint
Think about showing results page by page.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in this pagination query
Which option shows the correct syntax for paginating results with LIMIT and OFFSET in PostgreSQL?
PostgreSQL
SELECT * FROM products ORDER BY price DESC LIMIT 10 OFFSET 20;
ASELECT * FROM products ORDER BY price DESC OFFSET 20 LIMIT 10;
BSELECT * FROM products ORDER BY price DESC LIMIT 10 OFFSET 20;
CSELECT * FROM products ORDER BY price DESC LIMIT OFFSET 20 10;
DSELECT * FROM products ORDER BY price DESC LIMIT 10, OFFSET 20;
Attempts:
2 left
💡 Hint
LIMIT comes before OFFSET in PostgreSQL syntax.
optimization
advanced
2:00remaining
Why can OFFSET cause performance issues on large tables?
What is the main reason using a large OFFSET value can slow down pagination queries?
AOFFSET duplicates rows in the result set
BOFFSET causes the database to lock the entire table
COFFSET disables the use of indexes completely
DThe database must scan and skip all rows before the OFFSET, even if not returned
Attempts:
2 left
💡 Hint
Think about how the database finds the starting row.
🔧 Debug
expert
2:30remaining
Why does this pagination query return duplicate rows on page 2?
Given this query for page 2:

SELECT * FROM orders ORDER BY created_at LIMIT 10 OFFSET 10;

Sometimes rows appear duplicated across pages. What is the most likely cause?
AThe ORDER BY column <code>created_at</code> has duplicate values causing unstable ordering
BThe OFFSET value is too small
CLIMIT and OFFSET are reversed in the query
DThe table has no primary key
Attempts:
2 left
💡 Hint
Think about how rows with the same order value are sorted.