Bird
0
0

You have a REST API that uses keyset pagination with a composite cursor of (score DESC, id ASC). Which SQL WHERE clause correctly fetches the next page?

hard📝 Application Q9 of 15
Rest API - Pagination Patterns
You have a REST API that uses keyset pagination with a composite cursor of (score DESC, id ASC). Which SQL WHERE clause correctly fetches the next page?
AWHERE (score, id) < (:last_score, :last_id)
BWHERE score < :last_score OR (score = :last_score AND id > :last_id)
CWHERE score > :last_score OR (score = :last_score AND id < :last_id)
DWHERE score <= :last_score AND id >= :last_id
Step-by-Step Solution
Solution:
  1. Step 1: Analyze sorting directions

    Score is DESC, so next page means score less than last_score; id ASC breaks ties.
  2. Step 2: Construct WHERE clause for composite cursor

    WHERE score < last_score OR (score = last_score AND id > last_id) correctly fetches next rows.
  3. Final Answer:

    WHERE score < :last_score OR (score = :last_score AND id > :last_id) -> Option B
  4. Quick Check:

    Composite cursor with mixed order = A [OK]
Quick Trick: Invert comparison for DESC keys, use OR for tie-break [OK]
Common Mistakes:
  • Using > instead of < for DESC key
  • Mixing id comparison direction
  • Using AND instead of OR

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes