SQL Joins
SQL Joins
The SQL JOIN statement is used to combine rows from two tables based on a
common column and selects records that have matching values in these columns.
The main purpose of Join is to retrieve the data from multiple tables in other words
Join is used to perform multi-table queries.
Here emp_dets can be joined with supervisor_dets based on the common column
supervisor-id to retrieve the supervisor data for a particular employee.
Types of JOINS in SQL
Depending on the users' needs, there are several types of joins. These joins are
broadly classified into four types,
INNER JOIN
LEFT JOIN
RIGHT JOIN
FULL OUTER JOIN
IN DETAIL
The inner join returns matching rows from both tables; therefore, it is also known as
Equi join. If we don’t specify the inner keyword, SQL performs the inner join
operation.
SQL LEFT JOIN OR LEFT OUTER JOIN
The SQL LEFT JOIN combines two tables based on a common column. It then
selects records having matching values in these columns and the remaining rows
from the left table.
In the below example, the left outer join returns the following rows:
Matched rows: Emp ID 1 and 2 exists in both the left and right tables.
Unmatched row: Emp ID 3 doesn’t exist on the right table. Therefore, we have a
NULL value in the query output.