Section outline
-
Topics Objective
- Understand how to join multiple tables using different types of join.
Topics Outcomes
- Able to solve problem using different types of join.
SQL JOIN
A JOIN clause is used to combine rows from two or more tables, based on a related column between them.
Different Types of SQL JOINs
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
-
The INNER JOIN keyword selects records that have matching values in both tables.
-
The LEFT JOIN keyword returns all records from the left table (table1), and the matched records from the right table (table2). The result is NULL from the right side, if there is no match.
-
The RIGHT JOIN keyword returns all records from the right table (table2), and the matched records from the left table (table1). The result is NULL from the left side, when there is no match.
-
The FULL OUTER JOIN keyword returns all records when there is a match in left (table1) or right (table2) table records.
Note:
- FULL OUTER JOIN can potentially return very large result-sets!
- FULL OUTER JOIN and FULL JOIN are the same.
-