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). 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). What does this query return?
SELECT COUNT(*)
FROM Emp a, Emp b
WHERE a.salary < b.salary;
  1. A. 14
  2. B. 49
  3. C. 15
  4. D. 21

Correct answer: A. 14

Only the 6 non-NULL salaries can satisfy the condition. Of the C(6, 2) = 15 unordered pairs, exactly one ordering of each satisfies '<', except the tied pair (70000, 70000), which satisfies neither: 15 − 1 = 14.

More DBMS and SQL questions

Exams that ask this topic