Professional Documents
Culture Documents
Different Types of SQL JOINs
Different Types of SQL JOINs
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
CROSS JOIN: Returns Cartesian product of 2 tables
INNER JOIN:
SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;
SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;
Right join:
SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name = table2.column_name;
FULL JOIN:
SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name = table2.column_name
WHERE condition;
SELECT column_name(s)
FROM table1
CROSS JOIN table2
otherDepartment
id departmentname
1 IT
2 PAYROLL
3 HR
4Other Department
4 ROWS DEPARTMENT
10*4=40
8
{A,B,C} {X,Y,Z}
{AX,AY,AZ,BX,BY,BZ,CX,CY,CZ}
3 * 3= 9
{A,B,C} {Q,U,I,O,P}
{AQ,AU,AI,AO,AP,BQ,BU}