Trace pages after order totals change

A dashboard uses pagination to display orders from a PostgreSQL table. Initially, orders contains exactly these seven records. Each order_id is unique, and total_usd is an exact order total in US dollars.


order_id

total_usd

501

150

502

120

503

180

504

90

505

150

506

110

507

100


The first page is fetched with:


SQL
SELECT order_id
FROM orders
ORDER BY total_usd DESC, order_id ASC
LIMIT 3 OFFSET 0;


After the first page is fetched, two orders are added: order 508 with a total of 200 USD and order 509 with a total of 150 USD. Order 507 is also changed from 100 USD to 175 USD. No other records change, and no records are deleted.


The second page is then fetched with:


SQL
SELECT order_id
FROM orders
ORDER BY total_usd DESC, order_id ASC
LIMIT 3 OFFSET 3;


Assume each query sees the table as it exists when that query runs; the first page retains the IDs it originally displayed.


Determine both quantities as exact integer counts:

  • The number of distinct order IDs appearing on both fetched pages.
  • The number of order IDs in the final nine-row table that appeared on neither fetched page.
Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Single Table Queries Questions: