Back to articles list Articles Cookbook
9 minutes read

The Perfect Match: SQL Joins Explained

Not every invitation leads to a perfect match — and the same is true in SQL. This article explains SQL JOINs using a party guest list example, helping you understand how different JOIN types decide which records appear in the result.

February is the month of love. Dating apps talk about matches, invitations go out for Valentine’s events, and everyone hopes things line up the right way.

In SQL, we deal with matching all the time — just in a more practical way. Data is often spread across multiple tables. To analyze it, we need to combine tables based on matching values. That’s exactly what SQL JOINs do. They connect rows from different tables using a shared column and decide which records appear together in the result.

For beginners, this can feel abstract at first. Terms like INNER JOIN or LEFT JOIN describe precise rules, but without a clear picture, it’s easy to lose track of what’s actually happening.

Master the Art of the Match
If you want to skip the guesswork and start writing queries like a pro, the SQL JOINs course on LearnSQL.com is your perfect date. With 93 hands-on exercises, it’s designed to take you from "It's Complicated" to "SQL Expert" using real-world scenarios. It’s the fastest way to make JOINs second nature.

In this article, we’ll use a simple Valentine’s Day metaphor to explain SQL JOINs in a clear, intuitive way.

The Setup

Imagine you’re organizing a party. It could be a Valentine’s event, a party for singles, or just a casual get-together — the details don’t really matter.

Before the party, you create a list of people you invited. The party takes place, and afterward you can see what actually happened:

  • some invited people showed up
  • some invited people didn’t show up
  • and a few people showed up even though they weren’t invited

As a result, you end up with a second list: the people who attended the party. Now you have two lists:

  • people who were invited
  • people who showed up

In SQL terms, this gives us two tables. One table stores the people who were invited to the party, created before the event. The second table stores the people who actually showed_up, based on what happened in reality. Some records appear in both tables, some appear only in one. SQL JOINs help us compare these tables and decide which records we want to see together in the result.

invited

id name email
1 Alice alice@email.com
2 Bob bob@email.com
3 Carol carol@email.com
4 Dave dave@email.com

showed_up

id name arrived_at
1 Alice 2026-02-14 19:08:00
3 Carol 2026-02-14 19:22:00
5 Eve 2026-02-14 19:40:00

Alice and Carol were invited and showed up.
Bob and Dave were invited but didn’t attend.
Eve showed up without an invitation.

Comparing these two lists gives you different answers, depending on what you want to know.

INNER JOIN: The People Who Were Invited and Showed Up ❤️

An INNER JOIN is the most common way to combine tables. It looks for the "perfect match" between your two lists. In our party scenario, it returns only the people who:

  1. Were on the invited list.
  2. AND actually showed_up.

If someone was invited but didn't come (like Bob), they are left out. If someone showed up but wasn't on the list (like Eve), they are also left out. Only the overlapping "matches" make the cut.

Here is a pro tip for beginners: INNER JOIN is the standard. In SQL databases, if you simply write JOIN, the database assumes you mean INNER JOIN. It is the "default" setting for data relationships because, most of the time, we only want to see the records where both sides agree.

Now we can write an INNER JOIN that returns only invited guests who attended:

SELECT
  i.id,
  i.name,
  i.email,
  s.arrived_at
FROM invited AS i
INNER JOIN showed_up AS s
  ON i.id = s.id
ORDER BY s.arrived_at;

Result

id name email arrived_at
1 Alice alice@email.com 2026-02-14 19:08:00
3 Carol carol@email.com 2026-02-14 19:22:00

Alice and Carol appear because their id exists in both tables. Bob and Dave are excluded because they didn’t show up. Eve is excluded because she wasn’t invited, so there’s no matching row in the invited list.

In real work, INNER JOIN answers questions like:

  • Which invited users logged in?
  • Which customers placed an order?
  • Which emails were sent and opened?

If there’s no match on both sides, the record simply doesn’t appear in the result.

LEFT JOIN: Everyone Who Was Invited 💌

A LEFT JOIN starts with the invited table. That means every invited person appears in the result — whether they showed up or not.

  • if someone showed up, you see their attendance data
  • if they didn’t, the columns from the showed_up table contain NULL. NULL simply means: no matching record was found.

Here’s a LEFT JOIN that shows everyone who was invited, along with arrival time if they attended:

SELECT
  i.id,
  i.name,
  i.email,
  s.arrived_at
FROM invited AS i
LEFT JOIN showed_up AS s
  ON i.id = s.id
ORDER BY i.id;

Result

id name email arrived_at
1 Alice alice@email.com 2026-02-14 19:08:00
2 Bob bob@email.com NULL
3 Carol carol@email.com 2026-02-14 19:22:00
4 Dave dave@email.com NULL

Bob and Dave appear in the result even though they didn’t attend. The NULL simply indicates that no matching row was found in the showed_up table.

In practice, LEFT JOIN is useful when you want to ask:

  • Who did we invite, even if they didn’t come?
  • Which users signed up but never logged in?
  • Which customers never placed an order?

That’s why LEFT JOIN is one of the most commonly used JOINs in reporting and analysis.

Pro Tip: The "Safe" Join

In the professional world, LEFT JOIN is often the "go-to" choice for reporting. Why? Because it’s safe. It ensures you don't accidentally "delete" people from your report just because they haven't taken an action yet. If you want a list of all customers and their orders, a LEFT JOIN ensures that even customers who haven't bought anything yet are still counted.

RIGHT JOIN: Everyone Who Showed Up 🤷

A RIGHT JOIN works the same way as a LEFT JOIN, but from the other side. It starts with the showed_up list instead of the invited list. That means:

  • every person who came to the party appears in the result
  • if they were invited, you see their invitation details
  • if they weren’t, the invitation columns contain NULL

This naturally includes people who showed up without an invitation.

Here’s a RIGHT JOIN that shows everyone who showed up, whether they were invited or not:

SELECT
  s.id,
  i.name,
  i.email,
  s.arrived_at
FROM invited AS i
RIGHT JOIN showed_up AS s
  ON i.id = s.id
ORDER BY s.arrived_at;

Result

id name email arrived_at
1 Alice alice@email.com 2026-02-14 19:08:00
3 Carol carol@email.com 2026-02-14 19:22:00
5 NULL NULL 2026-02-14 19:40:00

Eve appears in the result even though she wasn’t invited. The NULL values in the invitation columns simply mean there was no matching record in the invited table.

RIGHT JOIN is less common in practice because you can usually rewrite it as a LEFT JOIN by switching the table order. Still, understanding how it works helps you read and reason about SQL code written by others.

FULL OUTER JOIN: The Complete Party Report 💝

A FULL OUTER JOIN shows everything. It combines both tables and keeps all records from both sides, whether a match exists or not.

That means you see:

  • people who were invited and showed up
  • people who were invited but didn’t come
  • people who showed up without an invitation

Nothing is filtered out.

Here’s a FULL OUTER JOIN that produces the complete party report:

SELECT
  i.id AS invited_id,
  i.name,
  i.email,
  s.arrived_at
FROM invited AS i
FULL OUTER JOIN showed_up AS s
  ON i.id = s.id
ORDER BY i.id, s.id;

Result

invited_id name email arrived_at
1 Alice alice@email.com 2026-02-14 19:08:00
2 Bob bob@email.com NULL
3 Carol carol@email.com 2026-02-14 19:22:00
4 Dave dave@email.com NULL
NULL NULL NULL 2026-02-14 19:40:00

This result shows the full story:

  • Alice and Carol were invited and showed up
  • Bob and Dave were invited but didn’t attend
  • Eve showed up without an invitation

FULL OUTER JOIN is useful when you want the complete picture and don’t want to lose any records from either table. It’s especially helpful for audits, data checks, and high-level reporting, where missing data matters just as much as matching data.

Same Data, Different Questions

The most important thing to remember about SQL JOINs is this:

The data does not change.
Only the question changes.

When you switch from an INNER JOIN to a LEFT JOIN or a FULL OUTER JOIN, you’re not modifying the tables. You’re only changing the rules that decide which records appear in the result set.

Once you stop thinking of JOINs as something mysterious and start thinking of them as filters applied to two lists, they become much easier to reason about.

This shift in perspective is often the moment when JOINs finally “click” for beginners.

From Party Guests Back to SQL Tables

The party example is just a way to make the logic visible. The same pattern appears everywhere in real SQL work.

For example:

  • customers and orders
  • users and logins
  • emails sent and emails opened

In every case, you are working with two lists and asking variations of the same questions:

  • Who appears in both lists?
  • Who appears only on one side?
  • Who do I want to include in my result, even if something is missing?

SQL JOINs exist to answer exactly these questions. Once you understand how they work with a simple guest list, applying the same logic to real tables becomes straightforward.

Conclusion: Choose the JOIN That Fits the Question

In SQL, as in romance, there is no single "best" match. There is only the JOIN that fits the question you’re asking.

  • Sometimes you want only confirmed, mutual matches (INNER JOIN).
  • Sometimes you need to see who hasn't responded yet (LEFT JOIN).
  • Sometimes you want the full, messy, beautiful picture of everyone involved (FULL OUTER JOIN).

Once you stop seeing JOINs as abstract code and start seeing them as the logic of relationships, you unlock the true power of relational databases.

Understanding the theory is a great first date, but mastery comes from practice. If you want to stop second-guessing your syntax and start writing complex queries with confidence, the SQL JOINs course is the perfect next step. You’ll move past the guest list and work with professional datasets, building the muscle memory you need for a career in data.

And if you’re ready for a serious, long-term relationship with your career, the All Forever SQL Package gives you lifetime access to every course we offer—from basic queries to advanced data analysis. It’s the ultimate gift to your future self.

Don't let your data stay "Complicated." Start your journey toward a perfect match today.