SQL

SQL FULL JOIN With Examples

SQL Full Join

The SQL FULL JOIN combines the results of both left and right outer joins. In full join all the row listed by join both side.

The joined table will contain all records from both the tables and fill in NULLs for missing matches on either side.

SQL LEFT JOIN. Avtartime

SELECT column_names
FROM table_name_1
FULL OUTER JOIN table_name_2 ON table_name_1.column_name = table_name_2.column_name;

For example, just see below and try to understand

Table -1 CUSTOMERS Table is as follows. Here we are taking 5 records with 3 columns as (CustomerId, CustomerName, and CustomerAge)   

+------------+--------------+-------------+
| CustomerId | CustomerName | CustomerAge |
+------------+--------------+-------------+
|          1 | John         |          25 |
|          2 | Smith        |          27 |
|          3 | Lulia        |          32 |
|          4 | Kristin      |          26 |
|          5 | Martin       |          22 |
+------------+--------------+-------------+

 Table -2  Orders Table is as follows. Here we are taking 4 records with 4 columns as (OrderId, OrderName, CustomerId, and Amount)

+---------+-----------+------------+--------+
| OrderId | OrderName | CustomerId | Amount |
+---------+-----------+------------+--------+
|       1 | Pizza     |          2 |    150 |
|       2 | Burger    |          2 |     50 |
|       3 | Noddle    |          4 |     30 |
|       4 | Ice Cream |          5 |     20 |
+---------+-----------+------------+--------+
SELECT customers.CustomerName,orders.OrderName,orders.Amount
FROM customers
FULL OUTER JOIN orders on orders.CustomerId=customers.CustomerId

As a result for above query

+--------------+-----------+--------+
| CustomerName | OrderName | Amount |
+--------------+-----------+--------+
| John         | NULL      |   NULL |
| Smith        | Pizza     |    150 |
| Smith        | Burger    |     50 |
| Lulia        | NULL      |   NULL |
| Kristin      | Noddle    |     30 |
| Martin       | Ice Cream |     20 |
+--------------+-----------+--------+

For more joins, you can check here

Sign Up for getting more new articles directly in your mail Inbox. 

Also Read  SQL INNER JOIN With Examples

About the author

Avtar

I am a blogger and I always believes in sharing a knowledge and happiness because happiness is the last journey of life.

Leave a Comment

Share2
Tweet
Pin
+1
Share
2 Shares