If you’ve ever worked with relational databases, you’ve probably come across the term JOIN. Joins are one of SQL’s most powerful features, allowing you to combine rows from two or more tables based on related columns.
In this post, we’ll break down the four most common types of joins—INNER, LEFT, RIGHT, and FULL OUTER JOIN with beginner-friendly explanations, SQL examples to help you understand how they work and when to use them.
What Is a JOIN in SQL?
A JOIN is used in SQL to combine data from two or more tables based on a related column, usually a primary key in one table and a foreign key in the other. This allows you to create richer, more complete results from separate data sources whether you’re connecting customers to orders, users to actions, or products to inventory.
INNER JOIN – Getting Only the Matches
Let’s kick things off with the INNER JOIN, one of the most commonly used SQL joins. It only returns rows where there is a match in both tables kind of like saying, “show me only where the two datasets overlap”.
To illustrate, we will work with two sample tables: users and orders.
Table 1: users
This table contains some basic info about our users

Table 2: orders
And this one shows the orders placed, linked to the user by user_id

What INNER JOIN Does
An INNER JOIN will return only the rows where a user has placed at least one order, so if someone appears in the users table but hasn’t placed any orders, they’ll be excluded.
https://gist.github.com/salmah52/54a396b4f59a7c3cab0c04d97cf028b1
Result:

What Happened Here?
- John appears twice because he has two matching orders.
- Helen also appears twice, same reason.
- Andrew (who didn’t place any orders) is not included.
- Every row in the result exists in both tables based on the join condition.
In Set Theory Terms
You can think of INNER JOIN like the intersection of two sets, only the shared parts make it into the result.
LEFT JOIN – Everything from the Left (Plus Matches from the Right)
Now let’s talk about the LEFT JOIN, also known as a LEFT OUTER JOIN. This type of join brings everything from the left table and pulls in matching rows from the right table if they exist. If there’s no match, the result will still include the row from the left, but with NULL values from the right.
We’ll continue using our users and orders tables:
What LEFT JOIN Does
A LEFT JOIN returns all rows from the users table, and any matching data from the orders table based on the condition. If a user has no orders, their order-related columns will just show up as NULL.
https://gist.github.com/salmah52/b575ebaeb6b8b80ac8e234914063d4a3
Result:

What This Tells Us:
- Every user appears in the result.
- Users with orders are joined multiple times (e.g., John and Helen).
- Users without orders (like Andrew) are still listed, but with
NULLin theamountcolumn.
In Set Theory Terms
Think of this like saying: “Give me everything from Set A (users), and where Set B (orders) overlaps, fill in the details.”
This is Set A + (A ∩ B).

RIGHT JOIN – Everything from the Right (Plus Matches from the Left)
Now let’s flip the script. A RIGHT JOIN (also called RIGHT OUTER JOIN) is the opposite of a LEFT JOIN. It returns all rows from the right table, and any matching rows from the left table. If there’s no match on the left, those columns will show up as NULL.
We’ll keep using the same two tables: users and orders.
What RIGHT JOIN Does
A RIGHT JOIN grabs every row from the orders table (our right table), and joins it with matching data from the users table. If a particular order isn’t tied to a user (like if the user got deleted or moved), we still keep the order, and the user info shows as NULL.
https://gist.github.com/salmah52/bd0bb9314a8ecaa7bf3b1c36f8eb7b44

What You’re Seeing:
- Every order is included, no matter what.
- Orders with a matching user (like John and Helen) show full data.
- If an order didn’t have a user in the
userstable, thenameandagecolumns would beNULL.(In this case, alluser_ids have matches, so no NULLs appear.) - Try removing a user from the
userstable and re-running the query to see how RIGHT JOIN keeps the order even if the user is missing!
In Set Theory Terms
This join is all about Set B (orders) and whatever overlap it has with Set A (users). It’s like saying: “Give me everything from the right side, and whatever matches on the left.” This is Set B + (A ∩ B).

FULL OUTER JOIN – All In, Matches or Not
The FULL OUTER JOIN is like the big finale. it grabs everything from both tables. You’ll get all the rows from the left table, all the rows from the right table, and where there’s a match, it joins them. If there’s no match, SQL fills in the gaps with NULL. This join gives you the complete picture.
We’ll stick with our familiar users and orders tables:
N.B- I added a new order with user_id = 7, which doesn’t exist in the users table.
Table: orders
What FULL OUTER JOIN Does
A FULL OUTER JOIN returns every row from both tables. Where there’s a match between users.id and orders.user_id, the data is combined. If there’s no match, you’ll still see the row—with NULL in place of missing data.
https://gist.github.com/salmah52/8a8b3946aba36a50284a113852f445ca

What We’re Seeing:
- John and Helen are joined with their orders.
- Andrew appears even though he didn’t order anything (
NULLinamount). - The last row shows an order with
user_id = 7—no match inusers, sonameandageareNULL. - This is the most complete join—you’ll never lose any rows.
In Set Theory Terms
This is the union (A ∪ B) of both tables: All users + all orders, matched when possible.

Wrapping Up: Why Joins Matter
Joins are more than just a technical feature; they’re the backbone of powerful data analysis in SQL. Whether you’re exploring user behavior, linking orders to customers, or just trying to make sense of scattered tables, joins let you see the full picture.
Let’s quickly recap:
- INNER JOIN: Only matched data from both tables
- LEFT JOIN: All data from the left table, plus matches from the right
- RIGHT JOIN: All data from the right table, plus matches from the left
- FULL OUTER JOIN: Everything from both tables—matched or not
Understanding when and how to use each join type can transform your queries from simple to insightful. It’s one of the most fundamental steps in thinking like a data analyst or backend developer.
What’s Next?
Now that you know how these joins work:
- Try writing your own queries using different join types
- Play around with missing data to see how joins behave
- Explore more advanced joins (like self joins or cross joins) when you’re ready.
Still have questions or a specific JOIN scenario you’re stuck on? Drop it in the comments or reach out—happy to help clarify anything that’s still not clear.
Happy querying.
