Bird
0
0

Which of the following is the correct SQL snippet to implement keyset pagination for a table users ordered by id?

easy📝 Syntax Q12 of 15
Rest API - Pagination Patterns
Which of the following is the correct SQL snippet to implement keyset pagination for a table users ordered by id?
ASELECT * FROM users ORDER BY id LIMIT 10 OFFSET 20;
BSELECT * FROM users WHERE id > 20 ORDER BY id LIMIT 10;
CSELECT * FROM users WHERE id = 20 ORDER BY id LIMIT 10;
DSELECT * FROM users ORDER BY id DESC LIMIT 10 OFFSET 20;
Step-by-Step Solution
Solution:
  1. Step 1: Identify keyset pagination syntax

    Keyset pagination uses a WHERE clause with a key (like id > last_seen_id) and a LIMIT to fetch the next page.
  2. Step 2: Analyze each option

    SELECT * FROM users WHERE id > 20 ORDER BY id LIMIT 10; uses WHERE id > 20 with ORDER BY id LIMIT 10, which matches keyset pagination logic.
  3. Final Answer:

    SELECT * FROM users WHERE id > 20 ORDER BY id LIMIT 10; -> Option B
  4. Quick Check:

    Keyset uses WHERE key > last_key [OK]
Quick Trick: Keyset uses WHERE with key comparison, not OFFSET [OK]
Common Mistakes:
  • Using OFFSET instead of WHERE for pagination
  • Using equality (=) instead of greater than (>)
  • Not ordering results by the key column

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes