JOIN #
Combine multiple tables together. JOIN
is typically an INNER JOIN
, where results only include matches across both tables. Non-matches are excluded.
SELECT <table_1>.<field>, <table_2>.<field>
FROM <table_1>
JOIN <table 2>
ON <table_1>.<field> = <table_2>.<field>;
LEFT JOINS #
Keeps all the records from the first (left) table, regardless of match.
SELECT ...
FROM <table_1>
LEFT JOIN <table_2>
ON <table_1>.<field> = <table_2>.<field>;
CROSS JOIN #
Combine all rows across multiple tables (i.e., all possible combinations).
This often explodes.
Note there’s no ON
statement.
SELECT <table_1>.<field>, <table_2>.<field>
FROM <table_1>
CROSS JOIN <table_2>;