Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

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
 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;

OUTER JOIN:LEFT JOIN OR LEFT OUTER JOIN

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;

(*Full outer join is not supporting in my system. It is giving an


error.)
CROSS JOIN:

SELECT column_name(s)
FROM table1
CROSS JOIN table2

CROSS JOIN should not have ON clause.

Tom male 4000 1


Pam female 3000 3
John male 3500 1
Sample male 4500 2
Todd male 2800 2
Ben male 7000 1
Sara female 4800 3
Valarie female 5500 1
James male 6500 Null
Russell male 8800 Null

SELECT *FROM DEPARTMENT;


10 ROWS

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}

ONLY NON MATHCING ROWS FROM LEFT TABLE


ADD POST TYPE

You might also like