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;
- A. 700
- B. 300
- C. 200
- 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
- Table Orders(id, cust, city, amount) rows: (1, 'Ana', 'Pune', 500), (2, 'Ben', 'Delhi', NULL), (3, 'Ana', 'Pune', 300), (4, 'Chen'…
- R(A, B, C, D, E) has functional dependencies A → BC, CD → E and B → D. Which of the following is a candidate key?
- Account X holds 100. T1 reads X (100); T2 reads X (100); T1 writes X = 150 and commits; T2 writes X = 80 and commits. What is the final…
- Table Orders has a composite B-tree index on (city, amount). Which WHERE clause can use this index to narrow the search most effectively?
- Which of these queries is NOT valid in standard SQL?
- Table Orders(id, cust, city, amount) rows: (1, 'Ana', 'Pune', 500), (2, 'Ben', 'Delhi', NULL), (3, 'Ana', 'Pune', 300), (4, 'Chen'…