bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/SQL/SQL Tutorial
SQL•SQL Tutorial

SQL FULL JOIN

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind SQL FULL JOIN?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___(s)
3Order

Put the learning moves in the order that makes the concept easiest to apply.

If a row in the left table has no match in the right table, the result set includes the left row's data and NULL values for all columns of the right table.
The FULL JOIN returns all rows when there is a match in either the left or right table.
SQL FULL JOIN Example

Sql Full Join

The FULL JOIN returns all rows when there is a match in either the left or right table.

If a row in the left table has no match in the right table, the result set includes the left row's data and NULL values for all columns of the right table.

If a row in the right table has no match in the left table, the result set includes the right row's data and NULL values for all columns of the left table.

The FULL JOIN and FULL OUTER JOIN keywords are equal - the OUTER keyword is optional.

Note

FULL JOIN can potentially return very large result-sets!

FULL JOIN Syntax

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

Demo Database

Below is a selection from the "Customers" table:

CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
1Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany
2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitución 2222México D.F.05021Mexico
3Antonio Moreno TaqueríaAntonio MorenoMataderos 2312México D.F.05023Mexico

And a selection from the "Orders" table:

OrderIDCustomerIDEmployeeIDOrderDateShipperID
10308271996-09-183
103093731996-09-191
103107781996-09-202

SQL FULL JOIN Example

The following SQL statement selects all customers, and all orders:

Example

SELECT Customers.CustomerName, Orders.OrderID

FROM Customers

FULL JOIN Orders

ON Customers.CustomerID = Orders.CustomerID;

A selection from the result-set may look like this:

CustomerNameOrderID
Null10309
Null10310
Alfreds FutterkisteNull
Ana Trujillo Emparedados y helados10308
Antonio Moreno TaqueríaNull

Note

FULL JOIN returns all matching records from both tables whether the other table matches or not. So, if there are rows in "Customers" that do not have matches in "Orders", or if there are rows in "Orders" that do not have matches in "Customers", those rows will be listed as well.

Previous

SQL RIGHT JOIN

Next

SQL Self Join