CS FundamentalsModerateWipro · Cognizant technical pattern

Table Orders(id, cust, city, amount) rows: (1, 'Ana', 'Pune', 500), (2, 'Ben', 'Delhi', NULL), (3, 'Ana', 'Pune', 300), (4, 'Chen', 'Delhi', 700), (5, 'Dia', NULL, 200), (6, 'Ben', 'Delhi', 700). What does this query return?

Table Orders(id, cust, city, amount) rows: (1, 'Ana', 'Pune', 500), (2, 'Ben', 'Delhi', NULL), (3, 'Ana', 'Pune', 300), (4, 'Chen', 'Delhi', 700), (5, 'Dia', NULL, 200), (6, 'Ben', 'Delhi', 700). What does this query return?
SELECT DISTINCT amount FROM Orders
WHERE amount IS NOT NULL
ORDER BY amount DESC
LIMIT 1 OFFSET 1;
  1. A. 700
  2. B. 300
  3. C. 200
  4. D. 500

Correct answer: D. 500

Distinct non-NULL amounts in descending order: 700, 500, 300, 200. OFFSET 1 skips the first, so the result is 500 — the second-highest distinct amount. Without DISTINCT the second row would be the duplicate 700.

More DBMS and SQL questions

Exams that ask this topic