SQL FULL JOIN

SQL FULL JOIN clause is used to select all the matched records from either left or right side table.

SQL FULL JOIN Clause Syntax

SELECT Table1.Column1, Table1.Column2, ... , Table2.Column1, Table2.Column2, ...
FROM Table1
FULL JOIN Table2
ON Table1.ColumnName = Table2.ColumnName

SQL FULL JOIN Clause Example

Table: Employees

EmployeeId FirstName LastName Department Salary
203 Buucci Queshi Development 78000
204 Ghoie Yaahi Development 45800
205 Huillosihua Philibes Development 57000
308 Axedul Water Sales 57000

Table: Tickets

TicketID TicketNo EmployeeId
1 1847 203
2 1923 204
3 2004 205
4 2166 206

Select all the employees and all the tickes:

SELECT Employees.EmployeeId
           , Employees.FirstName
           , Employees.LastName
           , Tickets.TicketNo
FROM Employees
FULL JOIN Tickets
ON Employees.EmployeeId = Tickets.EmployeeId

The result will look like:

EmployeeId FirstName LastName TicketNo
203 Buucci Queshi 1847
204 Ghoie Yaahi 1923
205 Huillosihua Philibes 2004
308 Axedul Water
2166

Note: The employee Axedul doesn’t have a ticket and the ticket 2166 doesn’t have an employee, but they are all listed in the result.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>