Question 1
Each employee's manager_id is stored in the EMPLOYEES table; some employees have no manager, and several employees share the same manager. Which query returns the number of distinct managers that employees report to?
A. SELECT COUNT(manager_id) FROM employees;
COUNT(manager_id) counts every row whose manager_id is not null but keeps duplicates, so employees who share a manager are each counted, overstating the number of distinct managers.
B. SELECT COUNT(*) FROM employees;
COUNT(*) counts all rows, including the employees who report to no one, so it counts people rather than distinct managers.
C. SELECT COUNT(DISTINCT manager_id) FROM employees;Correct answer
COUNT(DISTINCT manager_id) discards the null manager_ids and collapses the repeated ids, leaving only the separate managers actually reported to (100, 101 and 106).
D. SELECT COUNT(DISTINCT NVL(manager_id, 0)) FROM employees;
Wrapping manager_id in NVL(...,0) converts the null manager_ids into a single value 0, which DISTINCT then counts as an extra 'manager', inflating the true distinct count by one.
Explanation
COUNT behaves differently according to its argument: COUNT(*) counts every row, COUNT(column) counts only rows where that column is not null, and COUNT(DISTINCT column) counts the distinct non-null values. Because some employees have no manager and several share a manager, only the distinct-non-null form yields the number of separate managers reported to.