Bird
0
0

Which SQL WHERE clause correctly handles pagination for multiple sorting keys?

hard📝 Application Q8 of 15
Rest API - Pagination Patterns
You want to implement keyset pagination on a REST API that returns blog posts sorted by published date and id (both ascending). Which SQL WHERE clause correctly handles pagination for multiple sorting keys?
AWHERE published_date > :last_date OR (published_date = :last_date AND id > :last_id)
BWHERE published_date >= :last_date AND id > :last_id
CWHERE (published_date, id) > (:last_date, :last_id)
DWHERE published_date > :last_date AND id > :last_id
Step-by-Step Solution
Solution:
  1. Step 1: Understand multi-column keyset pagination

    When sorting by multiple columns, use lexicographical comparison: first by date, then by id if dates equal.
  2. Step 2: Identify correct WHERE clause

    WHERE published_date > last_date OR (published_date = last_date AND id > last_id) correctly fetches next rows.
  3. Final Answer:

    WHERE published_date > :last_date OR (published_date = :last_date AND id > :last_id) -> Option A
  4. Quick Check:

    Multi-key pagination = C [OK]
Quick Trick: Use OR with tie-breaker for multi-column keyset [OK]
Common Mistakes:
  • Using tuple comparison unsupported by some DBs
  • Using AND instead of OR causing missed rows
  • Using >= causing duplicates

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes