🧚 주목! Beekeeper Studio는 빠르고 현대적이며 오픈 소스 데이터베이스 GUI입니다 다운로드
May 13, 2025 작성자: Matthew Rathbone

If you’ve ever tried to pull data from multiple MySQL tables and felt lost, you’re not alone. Joins are one of those concepts that seem intimidating at first but become incredibly powerful once you get the hang of them.

Think of joins as a way to tell MySQL “hey, I want to grab data from this table AND that table, but only where certain conditions match up.” Once you understand the basic patterns, you’ll be combining data like a pro.

🔖 Quick Reference: Need a quick lookup? Check out our SQL JOIN Cheat Sheet with all JOIN types, visual diagrams, and code examples in one place.

The Join Family Tree

At its core, a join lets you combine rows from different tables when they share something in common. It’s like introducing two groups of friends who have mutual connections.

Here’s the lineup of join types we’ll cover:

  • INNER JOIN - Only show me records that exist in both tables
  • LEFT JOIN - Show me everything from the left table, plus matches from the right
  • RIGHT JOIN - The opposite of LEFT JOIN (though honestly, most people just flip their tables around instead)
  • FULL JOIN - Everything from both tables (MySQL makes us work a bit for this one)
  • CROSS JOIN - Every possible combination (use with caution!)
  • SELF JOIN - When a table needs to talk to itself

INNER JOIN - The Perfectionist

INNER JOIN Venn diagram showing only the overlapping area between two tables

INNER JOIN is picky. It only gives you rows where both tables have matching data. Think of it as the intersection in a Venn diagram.

Example:

Let’s work with two simple tables - employees and departments:

-- Employees Table
+----+----------+-------------+
| id | name     | department_id|
+----+----------+-------------+
| 1  | Alice    | 1           |
| 2  | Bob      | 2           |
| 3  | Charlie  | NULL        |
+----+----------+-------------+

-- Departments Table
+----+-------------+
| id | department  |
+----+-------------+
| 1  | HR          |
| 2  | IT          |
+----+-------------+

INNER JOIN Query:

SELECT employees.name, departments.department
FROM employees
INNER JOIN departments ON employees.department_id = departments.id;

Result:

+-------+------------+
| name  | department |
+-------+------------+
| Alice | HR         |
| Bob   | IT         |
+-------+------------+

LEFT JOIN - The Inclusive One

LEFT JOIN Venn diagram showing the entire left table plus overlapping area

LEFT JOIN is more generous than INNER JOIN. It says “I want everything from the left table, and if there’s matching stuff in the right table, great! If not, I’ll just put NULL there.”

Notice how Charlie shows up this time, even though he doesn’t have a department:

LEFT JOIN Query:

SELECT employees.name, departments.department
FROM employees
LEFT JOIN departments ON employees.department_id = departments.id;

Result:

+---------+------------+
| name    | department |
+---------+------------+
| Alice   | HR         |
| Bob     | IT         |
| Charlie | NULL       |
+---------+------------+

RIGHT JOIN - The Flip Side

RIGHT JOIN Venn diagram showing the entire right table plus overlapping area

RIGHT JOIN is just LEFT JOIN with the tables flipped. Most developers avoid it and just rearrange their FROM clause instead - it’s less confusing that way.

RIGHT JOIN Query:

SELECT employees.name, departments.department
FROM employees
RIGHT JOIN departments ON employees.department_id = departments.id;

Result:

+-------+------------+
| name  | department |
+-------+------------+
| Alice | HR         |
| Bob   | IT         |
+-------+------------+

FULL JOIN - The Kitchen Sink Approach

FULL OUTER JOIN Venn diagram showing both entire tables

Here’s where MySQL gets a bit annoying - it doesn’t have a built-in FULL JOIN. But we can fake it with a UNION trick:

FULL JOIN Simulation:

SELECT employees.name, departments.department
FROM employees
LEFT JOIN departments ON employees.department_id = departments.id
UNION
SELECT employees.name, departments.department
FROM employees
RIGHT JOIN departments ON employees.department_id = departments.id;

Result:

+---------+------------+
| name    | department |
+---------+------------+
| Alice   | HR         |
| Bob     | IT         |
| Charlie | NULL       |
+---------+------------+

CROSS JOIN - The Chaos Creator

CROSS JOIN diagram showing all possible combinations between tables

CROSS JOIN is like that friend who invites everyone to meet everyone else at a party. It pairs every single row from the first table with every single row from the second table. With 3 employees and 2 departments, we get 6 combinations:

CROSS JOIN Query:

SELECT employees.name, departments.department
FROM employees
CROSS JOIN departments;

Result:

+-------+------------+
| name  | department |
+-------+------------+
| Alice | HR         |
| Alice | IT         |
| Bob   | HR         |
| Bob   | IT         |
| Charlie | HR       |
| Charlie | IT       |
+-------+------------+

SELF JOIN - The Introspective One

Self joins happen when a table references itself. The classic example is an employee table where some employees manage other employees.

Example:

Here’s a managers table where the mgr_id points back to another row in the same table:

-- Managers Table
+----+----------+--------+
| id | name     | mgr_id |
+----+----------+--------+
| 1  | Tom      | NULL   |
| 2  | Jerry    | 1      |
| 3  | Spike    | 1      |
+----+----------+--------+

SELF JOIN Query:

SELECT m1.name AS manager, m2.name AS employee
FROM managers m1
LEFT JOIN managers m2 ON m1.id = m2.mgr_id;

Result:

+---------+----------+
| manager | employee |
+---------+----------+
| Tom     | Jerry    |
| Tom     | Spike    |
| Jerry   | NULL     |
| Spike   | NULL     |
+---------+----------+

Wrapping Up

Joins might seem overwhelming at first, but they’re really just different ways of saying “show me data from multiple tables with these rules.” Start with INNER and LEFT joins - they’ll handle 90% of what you need to do.

The best way to get comfortable with joins is to practice with your own data. Create some test tables, throw in some sample data, and start experimenting. Pretty soon you’ll be joining tables left and right (pun intended).

And remember: if your join is returning way more rows than you expected, you probably did a CROSS JOIN by accident. We’ve all been there!

Beekeeper Studio는 무료 & 오픈 소스 데이터베이스 GUI입니다

제가 사용해 본 최고의 SQL 쿼리 & 편집기 도구입니다. 데이터베이스 관리에 필요한 모든 것을 제공합니다. - ⭐⭐⭐⭐⭐ Mit

Beekeeper Studio는 빠르고 직관적이며 사용하기 쉽습니다. Beekeeper는 많은 데이터베이스를 지원하며 Windows, Mac, Linux에서 훌륭하게 작동합니다.

Beekeeper의 Linux 버전은 100% 완전한 기능을 갖추고 있으며, 기능 타협이 없습니다.

사용자들이 Beekeeper Studio에 대해 말하는 것

★★★★★
"Beekeeper Studio는 제 예전 SQL 워크플로를 완전히 대체했습니다. 빠르고 직관적이며 데이터베이스 작업을 다시 즐겁게 만들어 줍니다."
— Alex K., 데이터베이스 개발자
★★★★★
"많은 데이터베이스 GUI를 사용해 봤지만, Beekeeper는 기능과 단순함 사이의 완벽한 균형을 찾았습니다. 그냥 작동합니다."
— Sarah M., 풀스택 엔지니어

SQL 워크플로를 개선할 준비가 되셨나요?

download 무료 다운로드