Question 1
Given the hr-mini data below: ``` DEPARTMENTS EMPLOYEES (salary) 10 Administration Alice 9000, Heidi 6700 20 Engineering Bob 6000, Carol 7500, Dave 4800 30 Sales Eve 5200, Frank 3900, Grace 8100 40 Research (no employees) ``` How many rows does the following query return? ```sql SELECT d.dept_name, e.first_name FROM departments d LEFT JOIN employees e ON d.dept_id = e.dept_id WHERE e.salary > 6000 ```
A. 4Correct answer
The WHERE predicate sits on the null-extended employees table and is applied after the outer join. Only Alice, Carol, Grace and Heidi earn more than 6000; the Research row and every employee at or below 6000 are removed, leaving 4 rows.
B. 5
Assumes a LEFT join always keeps the department row, so it counts Research as well (4 + 1). It overlooks that Research's employee salary is NULL, making NULL > 6000 UNKNOWN, so the WHERE clause discards that row.
C. 8
Recognizes that the WHERE on the outer table collapses the join to inner semantics (dropping Research) but forgets to also apply salary > 6000, counting all eight matched employees instead of only those above 6000.
D. 9
Treats the predicate as if it lived in the ON clause (or as non-filtering), leaving every row of the LEFT join in place: the eight employees plus the NULL-extended Research row.
Explanation
A join's ON clause decides which rows pair up; a WHERE clause filters the already-joined result. When a predicate on the null-extended (optional) table sits in WHERE, it is evaluated after the outer join, and for an unmatched row that column is NULL, so the comparison is UNKNOWN and the row is discarded — collapsing the outer join toward an inner join. Only genuinely matched rows that also satisfy the predicate remain.