SQL FULL OUTER JOIN Keyword
As per the name the SQL FULL JOIN returns all the records from both of the tables. Its like combining 2 tables even with allowance of empty values in columns.
Let’s take a look at the syntax.
SELECT column/columns FROM table_left FULL OUTER JOIN table_right ON table_left.column= table_right.column WHERE condition;
NOTE: You can use FULL OUTER JOIN or FULL JOIN, both are same.
Let’s take a look at the example and see the results. That will make more sense than just looking at the syntax.
SELECT c.CustomerName, o.OrderID FROM Customers AS c FULL OUTER JOIN Orders AS o ON c.CustomerID=o.CustomerID ORDER BY c.CustomerName;
I have included example tables in DEMO but unfortunately MySQL doesn’t have FULL OUTER JOIN keyword. So there is no working demo available. However, we can emulate them in the following format to get the same results.
Take a look at the following code:
SELECT * FROM Customers LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID UNION SELECT * FROM Customers RIGHT JOIN Orders ON Customers.CustomerID = Orders.CustomerID
Take a look at the explanation given by MySQL here.
database FULL JOIN SQL JOIN sql query