CS FundamentalsModerateTCS NQT · Infosys interview 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). How many rows 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). How many rows does this query return?
SELECT id FROM Orders WHERE city <> 'Pune';
  1. A. 4
  2. B. 2
  3. C. 3
  4. D. 6

Correct answer: C. 3

Rows 2, 4 and 6 (Delhi) qualify. Row 5 has city NULL, and NULL <> 'Pune' evaluates to UNKNOWN, which WHERE treats as false. 4 wrongly counts the NULL row.

More DBMS and SQL questions

Exams that ask this topic