Hey Guys, hope you are good.
I’m sorry I havent been able to write or create content for a while now. I have been ill for the past 10 days and am still recovering.
Anyhoo, lets get started with today’s topic
Use Of Self JOIN In SQL
Self JOIN as obvious by its meaning allows us to join to instances of the same table together. It is basically used when we have to find heirarchial relationships within a dataset.
For Example, we might need to match employees with their managers, in which case we will be using the same table employees and then joining two instances of it on the basis of employeeid and managerid.
SELECT e1.emp_name AS Employee, e2.emp_name AS Manager FROM employees e1
LEFT JOIN employees e2 ON e1.manager_id = e2.emp_id;
These are the results above for our self JOIN statement. While self JOIN maybe an important concept in SQL, I have not used it much at work and nor have i listened to other mention about it as well. I would suggest keep this concept in mind but dont use it unless you absolutely have to.
Exercise
Here’s what you need to do today:
Load the Hospital Records Dataset
Use a Self JOIN on patients table
Can you see any tangible results?
Comment about those results
If you dont understand self JOIN, you can always comment and dont worry if you dont understand self JOINs.
I am a BI Engineer working at a Data And AI Firm. I’m trying to help newbies in Data land their first data job and impact as many fellow data professionals as I can. Here’s my contact info:
ajmal7809@gmail.com
bideveloper_ (Discord)