Introduction to Data Analysis : SQL Reference Sheet
Description Diagram Syntax
An inner join matches each row of table1 table2 SELECT *
one table with rows of a second
col A col B col B col C FROM table1
table based on a common column.
The resulting table will only contain JOIN table2
a x = x d
rows where there is a match in both ON table1.id = table2.table1_id
b y = w e
the left and right tables.
c z = z f
INNER JOIN
col A col B col C
a x d
c z f
A left join matches each row of one table1 table2 SELECT *
table with rows of a second table
col A col B col B col C FROM table1
based on a common column. The
resulting table will only contain all LEFT JOIN table2
a x = x d
data from the first (left) table, and ON table1.id = table2.table1_id
b y = w e
additional data from the second
(right) table for where the c z = z f
LEFT JOIN
col A col B col C
a x d
b yz
c z f
A cross join combines all rows table1 table2 SELECT table1.col1,
of one table with all rows of table2.col2
another table. col A col B col C col D
FROM table1
a c e h
CROSS JOIN table2;
b d f i
g j
CROSS JOIN
col A col B col C col D
a c e h
b d e h
a c f i
b d f i
a c g j
b d g j
The command union allows table1 table2 SELECT *
us to stack one dataset on top FROM table1
col A col B col C col D
of the other.
UNION
a c e
SELECT *
b d f
FROM table2;
g
UNION
col A col B
a c
b d
e h
f i
g j