Big SQL Energy Beginner Course: Lesson 28 INNER JOINs & Aliases
Got BDE?⚡️
Hi BDEs! Welcome to Lesson 28 of the free Big SQL Energy Beginner Course⚡️ Today we’re learning about INNER JOINS in SQL!
Return to Big SQL Energy Beginner homepage here to access the other lessons:
If you’re new here:
💁🏽♀️ Who Am I?
I’m Jess Ramos, the founder of Big Data Energy and the creator of the BEST SQL course and community: Big SQL Energy⚡️. Check me out on socials: 🔗LinkedIn, 🔗Instagram, 🔗YouTube, and 🔗TikTok. And of course subscribe to my 🔗newsletter here for all my upcoming lessons and updates— all for free!
⚡️ What is Big SQL Energy?
🔗Big SQL Energy Intermediate is an intermediate SQL course designed to solve real-world business problems hands-on using realistic data and a modern tech stack. You’ll walk away with 2 SQL portfolio projects, portfolio building guidance, access to the Big Data Energy Discord community, and lots of confidence for you upcoming coding interviews! You also get access to all monthly events including masterclasses, office hours, and guest speakers. This course is all of the most important things I’ve learned on the job as a Senior Data Analyst in tech who grew from a $72K salary to over a $150K salary. And now I’m sharing it with YOU! It’s more than just another course— it’s a challenging program designed to upskill your SQL to the intermediate level, get ready to ace your live coding interviews, and build connections in the data community through the Discord and events.
Lesson 28: Inner Joins
Today we’re learning INNER JOINs, but if you want to learn left joins, full outer joins, right joins, anti joins, and self joins, head on over to the 🔗Intermediate Big SQL Energy course ⚡️
Sometimes when you're working with data, you need to combine data from multiple places-- you don't always have everything you need right in one table! Very often, you need to combine data from multiple tables into 1 query or output. Imagine you have orders data, and you want to also pull in relevant customer data. That's where joins come into play! Joins combine rows from multiple tables using a common column also known as a key. You can connect primary keys or foreign keys from multiple tables-- or even sometimes a primary key and a foreign key. It's really important to understand basic data modeling principles before you start combining data or you can end up with a bunch of duplicates or nulls and not realize how.
Below is the (very small and simple) data model for the Beginner Big SQL Energy course. The 🔗Intermediate Big SQL Energy course has a much larger and more realistic data model with over 15 tables! Here we can see that the orders table and customers table are connected by (aka related by via one-to-many relationship) the ID in the Customers table and the customer_ID in the Orders table. This is how we can join the tables!
The basic syntax of a join is:
select
*
from
table1 as t1
join
table2 as t2
on t1.key = t2.id
Note that using only the word join is the same as using inner join. An inner join is implied with only the word "join." An inner join is a type of join that ONLY includes rows that have a match in both tables. So if a key or ID is in one table and not the other, it's excluded from the output. Inner joins only include the rows that are in both tables-- think of the center of a Venn diagram.
In SQL, there are many other kinds of joins such as left joins, full outer joins, right joins, anti joins, and self joins. Knowing them all is necessary for data analytics, so head on over to the 🔗Intermediate Big SQL Energy course after you finish this one to learn the rest!
When joining tables, we need to find a common column between the two to match the rows and connect them. In the real world, there's not always a common column, and sometimes the common columns have very different names which makes it hard to find & identify the common column. However, in this course, I kept the naming schemas consistent to make the matching easier!
We can inner join together the Customers and Orders tables on their related keys below:
select
*
from
orders as ord
join
customers as cust
on ord.customer_id = cust.id
This will return ONLY rows with a match in both tables since it’s an inner join. So customers without orders and orders without customers will be excluded from the output. If you want to learn the other join types as well head on over to the 🔗Intermediate Big SQL Energy course.
The next few lessons will be mini case studies to practice our knowledge! If you’ve enjoyed the free BEGINNER Big SQL Energy course, grab my intermediate course. There are no deadlines or timelines for this course— you start and take as long as you want. It will take your beginner skills to the next level and get you ready to ace your interviews. DM me or email me at courses@bdeanalytics.com if you have questions on the intermediate course!
Return to Big SQL Energy Beginner homepage here to access the other lessons: