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 dept, MAX(salary)
FROM Emp
WHERE salary < 90000
GROUP BY dept
HAVING COUNT(*) > 1;
  1. A. IT 70000 and Sales 40000
  2. B. IT 90000
  3. C. IT 70000, Sales 40000 and HR 50000
  4. D. IT 70000

Correct answer: D. IT 70000

WHERE runs first and drops Kiran (90000) and Lata (NULL < 90000 is UNKNOWN). Remaining groups: HR 1, IT 2 (Ravi, Meena), Sales 1 (John), NULL 1. Only IT has COUNT > 1, with MAX 70000. Sales loses Lata before grouping.

More DBMS and SQL questions

Exams that ask this topic