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 – A Solution without JOIN

SQL SELF JOIN – A Solution without JOIN

Super Learner
0
Votes
1
Answer

Hello everyone!

Regarding the lecture about SELF JOINs I was wondering if the JOIN clause is necessary.
Following logic in the last solution using WHERE IN I created a query as follows:
SELECT
*
FROM
emp_manager
WHERE
emp_no IN (SELECT
manager_no
FROM
emp_manager);
The connection is also only in two rows of interest and the result is same.
Is this solution correct? Are there some cases, in which SELF JOIN would be necessary?

Best regards,
Maros J

1 Answer

365 Team
0
Votes

Hi Maros!
Thanks for reaching out.
The cases in which using a self-join can be advantageous have been described in the lecture. In this particular example, so long as you obtain the same output, then your query is more than valid. Thank you very much for sharing an alternative.
Why do we use a self-join in this lecture? Because we wanted to teach you how to use this tool. Otherwise, it is true that sometimes identical output can be obtained by using different queries.
Hope this helps.
Best,
Martin

I understand, thank you 🙂 . May I have one more question? Could be the solution with Self Join more efficient in term of time? If yes, maybe I should prefer the solution form your lecture in the future. Best, Maros.

3 months