Joining Tables with JOIN Clauses
This guide introduces the different types of JOINs (INNER, LEFT, RIGHT, CROSS) and demonstrates how to combine data from multiple tables.
Setup: Example Tables and Data
CREATE TABLE t1 ( a INT );
CREATE TABLE t2 ( b INT );
INSERT INTO t1 VALUES (1), (2), (3);
INSERT INTO t2 VALUES (2), (4);JOIN Examples and Output
INNER JOIN
SELECT * FROM t1 INNER JOIN t2 ON t1.a = t2.b;+------+------+
| a | b |
+------+------+
| 2 | 2 |
+------+------+
1 row in set (0.00 sec)CROSS JOIN
LEFT JOIN (t1 LEFT JOIN t2)
RIGHT JOIN (t1 RIGHT JOIN t2)
LEFT JOIN (t2 LEFT JOIN t1) - Simulating a RIGHT JOIN
Older (Implicit) JOIN Syntax
Understanding JOIN Types Summary
Joining Multiple Tables
See Also
Last updated
Was this helpful?

