Hey guys, hope you are good.
Today, we’ll be looking at LEFT JOIN in SQL. Please do read the day 11 because all JOIN posts will have the same datasets used and you need to know the difference between the joins.
So, let’s get started.
Use Of LEFT JOIN In SQL
LEFT JOIN is basically used when you want your left table basically the table you use in your from clause to be imported completely in the table you are joining on.
For example
Select * from table.employees e
left join table.salaries s on e.employeeid = s.employeeid
This code snippet above will import all of your employees table while leaving out unmatched rows from salaries table ( making them NULL).
Correction: In my previous post I wrote that LEFT JOIN is also the default join in SQL which is wrong. An INNER JOIN is the default join.
So, let’s get started.
Our results are the same in case of LEFT JOIN or INNER JOIN due to the reason that all the rows match in both tables already as verified in INNER JOIN.
This case is only true for these tables but in some case the rows don’t match.
So that’s it, we’ve covered LEFT JOIN today and will be moving towards a RIGHT JOIN tomorrow.
If you have any questions about today’s lecture do let me know in the comments.
Exercise
Here’s what you need to do today:
Load your Hospital Patient records table
Execute a LEFT JOIN between the patients and procedures table.
Comment if the results are different from an INNER JOIN or not.
I’m trying my best here to explain SQL concepts and since I’m creating free content for you guys, I would appreciate if you guys can buy me a coffee
Its not obligation, if you think my content is worth it, I would appreciate it through a coffee.
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)