MySQL JOINs: INNER, LEFT, RIGHT, CROSS and the FULL JOIN Workaround

MySQL 65 min min read Updated: Nov 27, 2026 Beginner
MySQL JOINs: INNER, LEFT, RIGHT, CROSS and the FULL JOIN Workaround
Beginner Topic 1 of 3

Why Joins?

Data is split across tables to avoid repetition. Customers live in customers and their purchases in orders. A join puts them back together using a shared column.

INNER JOIN

Keeps only rows that match on both sides:

sql SELECT c.name, o.id AS order_id, o.order_date, o.status FROM customers c INNER JOIN orders o ON o.customer_id = c.id ORDER BY o.id;

Result:

nameorder_idorder_datestatus
Asha Rao12025-01-10shipped
Asha Rao22025-02-14shipped
Ben Carter32025-02-20shipped
Chen Wei42025-03-01pending
Ben Carter52025-03-15cancelled
Eli Brown62025-04-02shipped
Asha Rao72025-04-20pending
Chen Wei82025-05-05shipped
Fatima Khan92025-05-11shipped
Ben Carter102025-06-01shipped

Dina has no orders, so she is missing from the result.

LEFT JOIN

Keeps every row of the left table. Unmatched right columns become NULL:

sql SELECT c.name, o.id AS order_id FROM customers c LEFT JOIN orders o ON o.customer_id = c.id ORDER BY c.id, o.id;

Result:

nameorder_id
Asha Rao1
Asha Rao2
Asha Rao7
Ben Carter3
Ben Carter5
Ben Carter10
Chen Wei4
Chen Wei8
Dina CohenNULL
Eli Brown6
Fatima Khan9

Anti Join: Rows with No Match

sql SELECT c.name FROM customers c LEFT JOIN orders o ON o.customer_id = c.id WHERE o.id IS NULL;

Result:

name
Dina Cohen

The same idea with NOT EXISTS is often clearer and equally fast in MySQL 8:

sql SELECT c.name FROM customers c WHERE NOT EXISTS (SELECT 1 FROM orders o WHERE o.customer_id = c.id);

Result:

name
Dina Cohen
WHERE vs ON in a LEFT JOIN A condition on the right table in WHERE turns a LEFT JOIN back into an INNER JOIN. Put it in ON to keep unmatched rows.
sql SELECT c.name, COUNT(o.id) AS shipped_orders FROM customers c LEFT JOIN orders o ON o.customer_id = c.id AND o.status = 'shipped' GROUP BY c.id, c.name ORDER BY c.id;

Result:

nameshipped_orders
Asha Rao2
Ben Carter2
Chen Wei1
Dina Cohen0
Eli Brown1
Fatima Khan1

RIGHT JOIN

The mirror image of a LEFT JOIN. Most people just swap the tables and use LEFT JOIN:

sql SELECT c.name, o.id AS order_id FROM orders o RIGHT JOIN customers c ON o.customer_id = c.id WHERE c.id IN (4, 5) ORDER BY c.id;

Result:

nameorder_id
Dina CohenNULL
Eli Brown6

Joining Three Tables

sql SELECT o.id AS order_id, c.name AS customer, p.name AS product, oi.quantity, oi.quantity * p.price AS line_total FROM orders o JOIN customers c ON c.id = o.customer_id JOIN order_items oi ON oi.order_id = o.id JOIN products p ON p.id = oi.product_id WHERE o.id IN (1, 2) ORDER BY o.id, p.id;

Result:

order_idcustomerproductquantityline_total
1Asha RaoLaptop1899.00
1Asha RaoHeadphones2158.00
2Asha RaoNotebook1035.00
2Asha RaoPen Pack420.00

JOIN ... USING

When both columns have the same name, USING is shorter and shows the column once:

sql SELECT order_id, name, quantity FROM order_items JOIN (SELECT id AS product_id, name FROM products) p USING (product_id) WHERE order_id = 1 ORDER BY product_id;

Result:

order_idnamequantity
1Laptop1
1Headphones2

CROSS JOIN

Every row with every row (a Cartesian product). Useful for generating combinations:

sql CREATE TABLE sizes (size VARCHAR(2)); CREATE TABLE colors (color VARCHAR(10)); INSERT INTO sizes VALUES ('S'), ('M'), ('L'); INSERT INTO colors VALUES ('red'), ('blue'); SELECT size, color FROM sizes CROSS JOIN colors ORDER BY size, color;

Result:

sizecolor
Lblue
Lred
Mblue
Mred
Sblue
Sred
Forgot the ON? In MySQL, JOIN without ON is allowed and acts like a CROSS JOIN. A forgotten condition multiplies your rows. Always check row counts.

Self Join

sql CREATE TABLE staff (id INT PRIMARY KEY, name VARCHAR(20), manager_id INT); INSERT INTO staff VALUES (1, 'Zara', NULL), (2, 'Yusuf', 1), (3, 'Xin', 1), (4, 'Wale', 2); SELECT e.name AS employee, COALESCE(m.name, '(top)') AS manager FROM staff e LEFT JOIN staff m ON m.id = e.manager_id ORDER BY e.id;

Result:

employeemanager
Zara(top)
YusufZara
XinZara
WaleYusuf

FULL OUTER JOIN Workaround

MySQL has no FULL OUTER JOIN. Combine a LEFT and a RIGHT join with UNION:

sql CREATE TABLE a (k INT, av VARCHAR(5)); CREATE TABLE b (k INT, bv VARCHAR(5)); INSERT INTO a VALUES (1, 'a1'), (2, 'a2'); INSERT INTO b VALUES (2, 'b2'), (3, 'b3'); SELECT a.k AS ak, b.k AS bk, a.av, b.bv FROM a LEFT JOIN b ON a.k = b.k UNION SELECT a.k, b.k, a.av, b.bv FROM a RIGHT JOIN b ON a.k = b.k ORDER BY ak, bk;

Result:

akbkavbv
NULL3NULLb3
1NULLa1NULL
22a2b2

Joins and Duplicates

A one-to-many join repeats the parent row. Counting after the join can double count. Count orders and items separately:

sql SELECT c.name, COUNT(DISTINCT o.id) AS orders, SUM(oi.quantity) AS items FROM customers c JOIN orders o ON o.customer_id = c.id JOIN order_items oi ON oi.order_id = o.id GROUP BY c.id, c.name ORDER BY c.id;

Result:

nameordersitems
Asha Rao320
Ben Carter314
Chen Wei224
Eli Brown13
Fatima Khan12

Common Beginner Mistakes

MistakeWhat happensFix
Condition on the right table in WHERE after LEFT JOINUnmatched rows vanishMove to ON
Missing join conditionRows multiplyAlways write ON
COUNT(*) after a one-to-many joinInflated countsCOUNT(DISTINCT ...)
Expecting FULL JOINSyntax errorLEFT + RIGHT with UNION
Joining on columns of different typesSlow, no indexSame type on both sides

Practice

  1. List each product with the number of units sold (include products never sold).
  2. Find customers who never ordered Electronics.
  3. Show employee and manager names with a self join.
  4. Build a FULL OUTER JOIN of two small tables.

Conclusion

Use INNER JOIN for matches, LEFT JOIN to keep one side, anti joins to find gaps, and UNION of left and right joins to imitate FULL JOIN. Put right-table filters in ON.

Quick Summary: INNER, LEFT, RIGHT, CROSS, self, anti, USING, FULL JOIN workaround.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators