Last answered:

31 Aug 2020

Posted on:

28 Aug 2020

0

SQL Self Join

Hello, 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
  1. use SELECT DISTINCT at the beginning of the query
  2. 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? Regards SJ
1 answers ( 0 marked as helpful)
Instructor
Posted on:

31 Aug 2020

0
Hi Simon! 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. Best,
Martin

Submit an answer