bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/SQL/SQL Tutorial
SQL•SQL Tutorial

SQL FULL JOIN

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

This chapter

Overview
46

Lessons

115m

Read time

1. SQL Tutorial2. Introduction to SQL3. SQL Syntax4. SQL SELECT Statement5. SQL SELECT DISTINCT Statement6. SQL WHERE Clause7. SQL ORDER BY Keyword8. SQL AND Operator9. SQL OR Operator10. SQL NOT Operator11. SQL INSERT INTO Statement12. SQL NULL Values13. SQL UPDATE Statement14. SQL DELETE Statement15. SQL SELECT TOP, LIMIT and FETCH FIRST16. SQL Aggregate Functions17. SQL MIN() F unction18. SQL MAX() Function19. SQL COUNT() Function20. SQL SUM() Function21. SQL AVG() Function22. SQL LIKE Operator23. SQL Wildcards24. SQL IN Operator25. SQL BETWEEN Operator26. SQL Aliases27. SQL Joins28. SQL INNER JOIN29. SQL LEFT JOIN30. SQL RIGHT JOIN31. SQL FULL JOIN32. SQL Self Join33. SQL UNION Operator34. SQL UNION ALL Operator35. SQL GROUP BY Statement36. SQL HAVING Clause37. SQL EXISTS Operator38. SQL ANY Operator39. SQL ALL Operator40. SQL SELECT INTO Statement41. SQL INSERT INTO SELECT Statement42. SQL CASE Expression43. SQL NULL Functions44. SQL Stored Procedures45. SQL Comments46. SQL Operators

On this page

Sql Full JoinFULL JOIN SyntaxDemo DatabaseSQL FULL JOIN Example