SQL SELF JOIN – A Solution without JOIN
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 answers ( 0 marked as helpful)
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
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