Hey Guys, hope you are good.
How’s learning SQL going for you? Do I need to slow down? Do I need to explain more or is it good for you?
Today, we’ll be looking into another concept of SQL. Concepts will start getting more complex now but, don’t worry I’m here I’ll try to keep everything as simple as possible and you can always ask questions in the comment.
So we’ll be looking at joins in SQL. Its similar to what joins means in English but there are some variants of JOIN in SQL.
We have four types of JOIN, which are as following:
INNER JOIN
FULL OUTER JOIN
LEFT JOIN (Default)
RIGHT JOIN
Joins are used to combine two tables together on the basis of one common column. Now it all depends on what data you want to and what is its grain. So if you want to see data over a region you’ll have to find similar region columns on both the tables and combine them on that common column. If you want to see combined data of stores you’ll have to join them on a common store column. So the join you have to use and the column you have to join on really depends on what data you want to see.
Today, we will be looking into INNER JOIN and what it does and we’ll be continuing with the rest variants in the coming days.
Use Of INNER JOIN In SQL
INNER JOIN is used when we want to see data common in both the tables. So something like an intersection that only selects data that is common in both of the tables, otherwise it will make the rest NULL.
Today, I’m going to be changing my dataset to a Restaurant Sales dataset from Maven Analytics because I need 2 tables to join and Video Games had only 1 table.
So, lets get started.
We can see that we have menu_item_id and item_id common in both tables. So we’ll start to join. Always remember to keep your transaction table first while joining. In this instance our transactional table is order_details.
So we’ve 12573 rows that have matched and are common in both the table. INNER JOIN matches the two columns and filters out anything that isn’t common in both of the tables.
So we’ve covered INNER JOIN today and we’re going to be moving towards a LEFT JOIN tomorrow. Stay Tuned!
Exercise
Here’s what you need to do today:
Download the Hospital Patient Dataset from Maven Analytics
Load the dataset
Use select * from to see the data in the patients table and procedures table.
Use INNER JOIN on both the tables.
Share your query and results in the chat thread.
If you have any confusions in the exercise or the concept of INNER JOIN you can always comment below.
If you want personal guidance and mentorship, you’re most welcome to get the paid subscription.
Start Querying Today!
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)