Table Emp(id, dept, salary) has rows (1,’HR’,3000), (2,’IT’,5000), (3,’IT’,4000), (4,’HR’,NULL), (5,’Ops’,2000). SELECT COUNT(DISTINCT dept) FROM Emp; What is the output?
Correct answer D. 3
Explanation
COUNT(DISTINCT dept) first removes duplicate department values and then counts what is left. The dept column holds HR, IT, IT, HR and Ops, which reduces to three distinct values: HR, IT and Ops. Answering 5 confuses it with COUNT(dept), which counts every non-null value including repeats.
Answer checked How we write and check questions
Discussion