The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
The best answers are voted up and moderated by our team

SQL Self Join

SQL Self Join

0
Votes
1
Answer

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 Answer

365 Team
0
Votes

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

×
LAST CHANCE
Ready to Learn Data Science?
50% OFF