You are currently viewing 4 SQL JOINs Explained Visually (With Real-World Examples) Best Guide for SQL Join
SQL Join

4 SQL JOINs Explained Visually (With Real-World Examples) Best Guide for SQL Join

  • Post author:
  • Post last modified:June 9, 2025
  • Reading time:4 mins read

What Are SQL JOINs?

In relational databases, data is often spread across multiple tables. SQL JOINs allow you to combine rows from two or more tables based on related columns, enabling comprehensive analysis and reporting.


SQL Join

🎯 Learning Objectives: SQL JOIN

By the end of this tutorial, you will:

βœ… Understand INNER, LEFT, RIGHT, and FULL OUTER JOIN
βœ… Apply JOINs to real-world scenarios
βœ… Use JOINs with filters, aliases, and multiple conditions
βœ… Visualize how data is combined across tables


🧠 Base Scenario (Employee – Department Relationship)

We’ll use two real-world inspired tables:

πŸ“‹ Table 1: Employees

EmpIDNameDeptIDSalary
1Alice10160000
2Bob10250000
3CharlieNULL40000
4David10455000
5Eva10365000

πŸ“‹ Table 2: Departments

DeptIDDeptNameLocation
101HRNew York
102ITSan Diego
103FinanceChicago
106MarketingBoston

βœ… Note: DeptIDs 104 (used by David) and 106 (no employee) are unmatched across tables.


1️⃣ INNER JOIN: SQL JOIN

πŸ” Definition

Returns only the rows where there is a match in both tables.

🧠 Analogy

You’re preparing a report of employees with assigned departments. If the department doesn’t exist, they are excluded.

πŸ’» SQL Query

SELECT E.Name, D.DeptName, D.Location

FROM Employees E

INNER JOIN Departments D ON E.DeptID = D.DeptID;

βœ… Output

NameDeptNameLocation
AliceHRNew York
BobITSan Diego
EvaFinanceChicago

❌ David (invalid DeptID = 104) and Charlie (no DeptID) are excluded.

πŸ“Š Visual Metaphor

[Employees] ∩ [Departments]

2️⃣ LEFT JOIN (LEFT OUTER JOIN): SQL JOIN

πŸ” Definition

Returns all records from the left table (Employees) and matching records from the right table (Departments). Unmatched departments β†’ NULL.

🧠 Analogy

You want a list of all employees, even if their department is not known or doesn’t exist.

πŸ’» SQL Query

SELECT E.Name, D.DeptName, D.Location

FROM Employees E

LEFT JOIN Departments D ON E.DeptID = D.DeptID;

βœ… Output

NameDeptNameLocation
AliceHRNew York
BobITSan Diego
CharlieNULLNULL
DavidNULLNULL
EvaFinanceChicago

βœ… All employees are listed, even those with missing or invalid DeptIDs.

πŸ“Š Visual Metaphor

[Employees] βŸ• [Departments]

Read also: How to Learn C++: A Beginner’s Guide for 2025, Best way To Learn C++

3️⃣ RIGHT JOIN (RIGHT OUTER JOIN): SQL JOIN

πŸ” Definition

Returns all records from the right table (Departments) and the matching rows from the left table (Employees). Unmatched employees β†’ NULL.

🧠 Analogy

You want a list of all departments, even if no employee belongs to them.

πŸ’» SQL Query

SELECT E.Name, D.DeptName, D.Location

FROM Employees E

RIGHT JOIN Departments D ON E.DeptID = D.DeptID;

βœ… Output

NameDeptNameLocation
AliceHRNew York
BobITSan Diego
EvaFinanceChicago
NULLMarketingBoston

βœ… All departments included. Marketing has no employees β†’ NULL in Name.

πŸ“Š Visual Metaphor

[Employees] βŸ– [Departments]

4️⃣ FULL JOIN (FULL OUTER JOIN): SQL JOIN

πŸ” Definition

Returns all records from both tables. Matched where possible, and NULL for non-matches.

🧠 Analogy

You want a complete picture β€” all employees and all departments, whether related or not.

πŸ’» SQL Query

SELECT E.Name, D.DeptName, D.Location

FROM Employees E

FULL OUTER JOIN Departments D ON E.DeptID = D.DeptID;

βœ… Output

NameDeptNameLocation
AliceHRNew York
BobITSan Diego
EvaFinanceChicago
CharlieNULLNULL
DavidNULLNULL
NULLMarketingBoston

πŸ“Š Visual Metaphor

[Employees] βˆͺ [Departments] (on DeptID)


πŸ§ͺ Advanced Examples

🎯 1. Find employees without a department

SELECT Name

FROM Employees

LEFT JOIN Departments ON Employees.DeptID = Departments.DeptID

WHERE Departments.DeptID IS NULL;

βœ… Result:

Name
Charlie
David

🎯 2. Find departments with no employees

SELECT DeptName

FROM Departments

LEFT JOIN Employees ON Departments.DeptID = Employees.DeptID

WHERE Employees.EmpID IS NULL;

βœ… Result:

DeptName
Marketing

🎯 3. Join with additional conditions (e.g., high earners in Finance)

SELECT E.Name, D.DeptName, E.Salary

FROM Employees E

INNER JOIN Departments D ON E.DeptID = D.DeptID

WHERE D.DeptName = ‘Finance’ AND E.Salary > 60000;

βœ… Result:

NameDeptNameSalary
EvaFinance65000

πŸ” JOIN Comparison Summary

SQL Join
JOIN TypeLeft Table IncludedRight Table IncludedNULLs Possible
INNER JOINβœ… if matchβœ… if match❌
LEFT JOINβœ… alwaysβœ… if matchβœ… Right table
RIGHT JOINβœ… if matchβœ… alwaysβœ… Left table
FULL OUTERβœ… alwaysβœ… alwaysβœ… Both sides

πŸ“¦ Practice: Table Creation & Sample Data

CREATE TABLE Employees (

    EmpID INT,

    Name VARCHAR(50),

    DeptID INT,

    Salary INT

);

INSERT INTO Employees VALUES

(1, ‘Alice’, 101, 60000),

(2, ‘Bob’, 102, 50000),

(3, ‘Charlie’, NULL, 40000),

(4, ‘David’, 104, 55000),

(5, ‘Eva’, 103, 65000);

CREATE TABLE Departments (

    DeptID INT,

    DeptName VARCHAR(50),

    Location VARCHAR(50)

);

INSERT INTO Departments VALUES

(101, ‘HR’, ‘New York’),

(102, ‘IT’, ‘San Diego’),

(103, ‘Finance’, ‘Chicago’),

(106, ‘Marketing’, ‘Boston’);


πŸŽ“ Final Thoughts

Understanding JOINs is fundamental to mastering SQL. Here’s a quick recap:

  • INNER JOIN: Only matching records β€” strict.
  • LEFT JOIN: All from the left, fill blanks from the right.
  • RIGHT JOIN: All from the right, fill blanks from the left.
  • FULL OUTER JOIN: Show everything β€” match where possible.
Learn With Khurshid
Learn With Khurshid

πŸ‘‰ Mastering JOINs allows you to build powerful queries, extract hidden insights, and unlock the true potential of your data.

Khurshid Anwar

I am a computer science trainer, motivator, blogger, and sports enthusiast. I have 25 years of training experience of Computer Science, Programming language(Java, Python, C, C++ etc).