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

SAMPLE SYNTAX

SELECT column_name(s)
FROM table1
INNER JOIN table2 ON table1.column_name = table2.column_name;

  • LEFT JOIN Or LEFT OUTER JOIN : Returns all records from the left table, and the matched records from the right table

LEFT JOIN SYNTAX

SELECT column_name(s)
FROM table1

LEFT JOIN table2 ON table1.column_name = table2.column_name;

  • RIGHT JOIN OR RIGHT OUTER JOIN: Returns all records from the right table, and the matched records from the left table

RIGHT JOIN SYNTAX

SELECT column_name(s)
FROM table1
RIGHT JOIN table2 ON table1.column_name = table2.column_name;

  • FULL JOIN OR FULL OUTER JOIN: Returns all records when there is a match in either left or right table

FULL JOIN SYNTAX

SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2 ON table1.column_name = table2.column_name;