Yogesh Chauhan's Blog

Is there a way to do a FULL OUTER JOIN in MySQL?

in SQL/MySQL on September 24, 2019

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.


Most Read

#1 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to uninstall Cocoapods from the Mac OS?

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
INNER JOIN in PostgresPostgresHow to convert an HTML radio buttons into a toggle switch using CSS?CSSDebugging in WordPress Part 3: SCRIPT_DEBUG and SAVEQUERIESWordPressSlider animation using CSS transform propertyCSSHow to Display Related Posts in WordPress?WordPressWhat is DevOps?MiscellaneousHow to vertically align a html radio button to it’s label?CSSWordPress: How to loop through ACF group fields?WordPressJavaScript Input Validation Theme Park Example using throw StatementJavaScriptHow to add and remove capabilities from a role in WordPress?WordPressWhat are Identifiers in JavaScript?JavaScriptHow to Use password_hash and password_verify to Secure Your User’s Data (Especially Passwords)?PHP