CS FundamentalsModerateProduct-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). How many rows 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). How many rows does this query return?
SELECT dept, COUNT(*) FROM Emp GROUP BY dept;
  1. A. 7
  2. B. 3
  3. C. 6
  4. D. 4

Correct answer: D. 4

Groups: HR, IT, Sales and one group for NULL (Dev). GROUP BY puts all NULLs in a single group even though NULL = NULL is not true in a WHERE clause.

More DBMS and SQL questions

Exams that ask this topic