SQL - FULL JOIN

The FULL Join condition returns values as per below rule:

  • All the matching data values from Table A and Table B.

  • All the non-matching data values from Left Table  i.e. Table A and Right Table i.e. Table B.

SYNTAX:

134.png

Where,

  • FULL JOIN                                 :   keyword used for FULL JOIN, in order to fetch all the matching and non matching records from                                                                                            both the table

  • Table_name1/Table_name2      : The name of the first/second table from where you want to fetch the data

  • Column1Name                           : The name of the columns of the table based on which you want to join.

 
 

EXAMPLE

Let us consider a demo database with two tables Persons & Salary. Following is the structure of both the tables:

Figure 35.1. PERSONS TABLE

135.png
136.png

Figure 35.2. SALARY TABLE

The following SQL statement selects all the matching and non –matching records from Persons table (Left Table) and Salary Table (Right table)

137.png

Figure 35.3. FULL OUTER JOIN OUTPUT

Note: FULL OUTER JOIN and FULL JOIN are the same.