CS FundamentalsHardProduct-company MCQ pattern

Table Emp(id, name, dept, salary, mgr) rows: (1, 'Asha', 'HR', 50000, NULL), (2, 'Ravi', 'IT', 70000, 1), (3, 'Meena', 'IT', 70000, 2), (4, 'John', 'Sales', 40000, 1), (5, 'Kiran', 'IT', 90000, 2), (6, 'Dev', NULL, 45000, 4), (7, 'Lata', 'Sales', NULL, 4). In the SQL standard (and in MySQL, PostgreSQL, Oracle), what does this query return?

Table Emp(id, name, dept, salary, mgr) rows: (1, 'Asha', 'HR', 50000, NULL), (2, 'Ravi', 'IT', 70000, 1), (3, 'Meena', 'IT', 70000, 2), (4, 'John', 'Sales', 40000, 1), (5, 'Kiran', 'IT', 90000, 2), (6, 'Dev', NULL, 45000, 4), (7, 'Lata', 'Sales', NULL, 4). In the SQL standard (and in MySQL, PostgreSQL, Oracle), what does this query return?
SELECT COUNT(*) FROM Emp
WHERE salary > ALL (SELECT salary FROM Emp
                    WHERE dept = 'Sales');
  1. A. 3
  2. B. 6
  3. C. 0
  4. D. 4

Correct answer: C. 0

The subquery returns {40000, NULL}. For any salary s > 40000, 's > ALL' becomes TRUE AND UNKNOWN = UNKNOWN; for s ≤ 40000 it is FALSE. No row gets TRUE, so the count is 0. Ignoring the NULL gives 4, the trap.

More DBMS and SQL questions

Exams that ask this topic