In the SQL SELF JOIN video in the SQL course, there is an exercise to use the emp_manager table to extract the record data for only the employees who are also managers.
Two solutions are given for to obtain the two row output we are looking for
- use SELECT DISTINCT at the beginning of the query
- use a WHERE statement in the query to connect back to the manager_no column in the emp_manager table
Isn’t there a third option which is to use GROUP_BY (instead of a WHERE statement) at the end of the query to group by e2.manager_no?
Option 3 gives the same result as 1 and 2 in the exercise. Is there a good reason why you wouldn’t use that option?
Thanks for reaching out.
We are aiming to provide exercises on using self joins, which is the topic of the section and lecture. That’s the main reason.
Otherwise, as it can happen in many other occasions, there may be several solutions to a given problem in SQL.
Hope this helps but please feel free to get back to us should you need further assistance. Thank you.