SQL Joins - Notes
1. INNER JOIN
Returns only the matching rows between two tables.
Syntax:
SELECT columns
FROM table1
INNER JOIN table2
ON table1.column = table2.column;
2. LEFT JOIN (LEFT OUTER JOIN)
Returns all rows from the left table and matched rows from the right table. Unmatched rows from the
right table will be NULL.
Syntax:
SELECT columns
FROM table1
LEFT JOIN table2
ON table1.column = table2.column;
3. RIGHT JOIN (RIGHT OUTER JOIN)
Returns all rows from the right table and matched rows from the left table. Unmatched rows from the
left table will be NULL.
Syntax:
SELECT columns
FROM table1
SQL Joins - Notes
RIGHT JOIN table2
ON table1.column = table2.column;
4. FULL JOIN (FULL OUTER JOIN)
Returns all rows when there is a match in one of the tables. Unmatched rows will have NULLs.
Syntax:
SELECT columns
FROM table1
FULL OUTER JOIN table2
ON table1.column = table2.column;
5. CROSS JOIN
Returns the Cartesian product of two tables. Every row in the first table is combined with all rows in
the second table.
Syntax:
SELECT columns
FROM table1
CROSS JOIN table2;
6. SELF JOIN
A self join is a regular join but the table is joined with itself.
Syntax:
SELECT A.columns, B.columns
SQL Joins - Notes
FROM table A, table B
WHERE condition;