Switching alias in subquery equality leads to different result
0
votes
1
answer
87
views
Trying to learn sql queries recently and as the title says I stumbled upon some "behavior" i didn't understand.
This query returns the managers from the database.
SELECT *
FROM employees e
WHERE EXISTS (SELECT * FROM employees f WHERE e.employee_id = f.manager_id)
However if I switch the aliases in the equality it returns all the employees.
SELECT *
FROM employees e
WHERE EXISTS (SELECT * FROM employees f WHERE f.employee_id = e.manager_id)
Isn't


employees e
and employees f
the same table but with different names? If so, why is then the alias order important?
Asked by Constantin Constantin
(1 rep)
Oct 29, 2018, 11:28 PM
Last activity: Oct 30, 2018, 10:25 AM
Last activity: Oct 30, 2018, 10:25 AM