There are three tables that may be used by a business to keep track of the absent days of its employees. It's from a collection of SQL puzzles by Joe Celko. The reader is tasked with concocting a DELETE statement to remove those employees who have accrued 40 or more absent days. And for that purpose we use a subquery. The one proposed by the author is this:
DELETE FROM Personnel WHERE emp_id = (SELECT A1.emp_id FROM Absenteeism AS A1 WHERE A1.emp_id = Personnel.emp_id GROUP BY A1.emp_id HAVING SUM(severity_points) >= 40);
And my question is, why go for a correlated one? Isn't it just more efficient to run something like one below?
DELETE FROM Personnel WHERE emp_id = (SELECT emp_id FROM Absenteeism GROUP BY emp_id HAVING SUM(severity_points) >= 40)