⏫Join Clauses
Last updated
Last updated
Here are the different types of the JOINs in SQL:
(INNER) JOIN
: Returns records that have matching values in both tables
LEFT (OUTER) JOIN
: Returns all records from the left table, and the matched records from the right table
RIGHT (OUTER) JOIN
: Returns all records from the right table, and the matched records from the left table
FULL (OUTER) JOIN
: Returns all records when there is a match in either left or right table
INNER JOIN
JOIN
(or explicitly INNER JOIN
) returns rows that have matching values in both tables.
LEFT JOIN
LEFT JOIN
returns all rows from the left table with corresponding rows from the right table. If there's no matching row, NULL
s are returned as values from the second table.
RIGHT JOIN
RIGHT JOIN
returns all rows from the right table with corresponding rows from the left table. If there's no matching row, NULL
s are returned as values from the left table.
FULL JOIN
FULL JOIN
(or explicitly FULL OUTER JOIN
) returns all rows from both tables – if there's no matching row in the second table, NULL
s are returned.
CROSS JOIN
CROSS JOIN
returns all possible combinations of rows from both tables. There are two syntaxes available.
NATURAL JOIN
NATURAL JOIN
will join tables by all columns with the same name.
NATURAL JOIN
used these columns to match rows:
city.id
, city.name
, country.id
, country.name
.
NATURAL JOIN
is very rarely used in practice.