<aside> 🔗 JOINs combine rows from multiple tables based on a related column between them.
</aside>
Returns only rows that have matching values in both tables.
SELECT
c.id, c.first_name,
o.order_id, o.sales
FROM customers AS c
INNER JOIN orders AS o
ON c.id = o.customer_id
Returns all rows from the left table, and matched rows from the right. NULL where no match.
SELECT
c.id, c.first_name,
o.order_id, o.sales
FROM customers AS c
LEFT JOIN orders AS o
ON c.id = o.customer_id
Returns all rows from the right table, and matched rows from the left.
SELECT
c.id, c.first_name,
o.order_id, o.sales
FROM customers AS c
RIGHT JOIN orders AS o
ON c.id = o.customer_id
Returns all rows from both tables. NULL where there is no match on either side.
SELECT
c.id, c.first_name,
o.order_id, o.sales
FROM customers AS c
FULL JOIN orders AS o
ON c.id = o.customer_id
SELECT *
FROM customers AS c
LEFT JOIN orders AS o
ON c.id = o.customer_id
WHERE o.customer_id IS NULL