Thursday, May 20, 2021

SQL Full Outer Join with example

 The FULL OUTER JOIN keyword returns all records when there is a match in left (table1) or right (table2) table records.

Syntax:

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

Example:

Lets take below two tables

Employee

EmpName

DeptID

Rafferty

31

Jones

33

Heisenberg

33

Robinson

34

Smith

34

Williams

null

Department


DeptID

DepName

31

Sales

33

Engineering

34

Clerical

35

Marketing

SQL Query:

SELECT e.EmpName, d.DepName  
    FROM Employees AS e   
        FULL OUTER JOIN  Department AS d ON e.DepID = d.DepID; 
Output:

EmpName

DepName

Rafferty

Sales

Jones

Engineering

Heisenberg

Engineering

Robinson

Clerical

Smith

Clerical

null

Marketing

Williams

null


Please visit related article below:

No comments:

Post a Comment