Home Data Engineering ETL & ELT Data Pipelines Tutorials Blog Databases Data Warehousing Big Data Cloud Data SQL Guides Python Guides Tools Glossary Resources About Contact
Beginner

SQL Joins Explained

INNER, LEFT, RIGHT and FULL joins explained with diagrams and sample queries.

Why Joins Matter

Relational databases store data across multiple related tables to avoid duplication. Joins let you combine rows from two or more tables based on a related column, such as a customer ID, so you can query them together.

Inner Join

An INNER JOIN returns only the rows that have matching values in both tables.

SQL
SELECT o.order_id, c.customer_name, o.order_amount
FROM orders o
INNER JOIN customers c
    ON o.customer_id = c.customer_id;

Left Join

A LEFT JOIN returns all rows from the left table, and matching rows from the right table. Unmatched right-side columns return NULL.

SQL
SELECT c.customer_name, o.order_id
FROM customers c
LEFT JOIN orders o
    ON c.customer_id = o.customer_id;

A RIGHT JOIN is the mirror of a left join — it returns all rows from the right table, and matching rows from the left table.

SQL
SELECT c.customer_name, o.order_id
FROM customers c
RIGHT JOIN orders o
    ON c.customer_id = o.customer_id;

Full Join

A FULL JOIN returns all rows from both tables, matching where possible and filling unmatched sides with NULL.

SQL
SELECT c.customer_name, o.order_id
FROM customers c
FULL JOIN orders o
    ON c.customer_id = o.customer_id;