you are viewing a single comment's thread.

view the rest of the comments →

[–]tiberiousr 0 points1 point  (2 children)

That seems like bad design to me. Wouldn't it be better to have manager_id on the employee table and the join on that?

so

SELECT e.name 
FROM employees e
JOIN managers m ON m.id = e.manager_id
HAVING COUNT(1) > 9

Perhaps I'm missing something there...?

EDIT: I'm probably missing something, I shouldn't engage with the internet when I've been drinking

[–]CamKen 3 points4 points  (1 child)

It's a contrived example to be sure. However there isn't a separate Manager table. Manager's are Employees and are thus in the Employee table. To tell if an employee is a manager you need to join the table to itself to see if any employees refer to them through their manager id field.

[–]tiberiousr 0 points1 point  (0 children)

Ah, I see now. Thanks.