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

Containers 101: What are containers?MiscThe fundamental difference between HAVING and WHERE clauses in PostgresPostgresHow to Create a Backup From Any Database in SQL?SQL/MySQLWhat is iFrame in HTML? Why do we need it?HTMLWhat happened to your Google Analytics Tracking ID, can’t find it?Misc2 Ways We Can Write Multiple Line Commands in PHPPHPHow can one check to see if a remote file exists using PHP?PHPHow to concatenate variable with string in Swift?SwiftPHP __construct() functionPHPA Quick Guide to Object-Oriented Programming in PHPPHPHow to apply style only to first child and/or only to children other than the first child?CSSHow to detect the Blog Page in WordPress?WordPress