YogeshChauhan . com

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.

amazon

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 How to Use SQL MAX() Function with Dates? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

Jun 16 What are Stored Procedures for SQL Server? Jun 16 What are Class Constants in PHP? Jun 15 A short basic guide on states in React Jun 15 How to define constants in PHP? Jun 15 How to define visibility for a property in PHP? Jun 15 How to use @if and @else in SCSS?

You might also like these

Canvas Drawing in HTML5HTMLHow to select an element using its ID without the high specificity of the ID selector?CSSStyling Lists with CSSCSSHow to use @if and @else in SCSS?SCSSWhat is Git?MiscAngular 9 time clock update every minute, second, hourAngularArray.from() Method in JavaScriptJavaScriptA simple example on grid ‘auto-fill’ vs ‘auto-fit’CSSCONCAT and CONCAT_WS Functions in PostgresPostgresHow to create a simple tab interaction using CSS?CSS3 Types of Arrays in PHPPHPWordPress: How to loop through a repeater field in ACF?WordPress