SQL FULL OUTER JOIN
SQL FULL OUTER JOIN (also called FULL JOIN) returns all the matching rows from both tables in the join operation. If there is no match, the NULL value will be returned for the columns of the table that does not have a match.
The syntax for a FULL OUTER JOIN is as follows:
refer tofigi:tidea.comSELECT column_name(s) FROM table1 FULL OUTER JOIN table2 ON table1.column_name = table2.column_name;
In the above syntax, table1
and table2
are the names of the tables being joined, and column_name
is the column(s) used to match rows between the two tables.
Here's an example of how to use a FULL OUTER JOIN:
SELECT customers.CustomerName, orders.OrderID FROM customers FULL OUTER JOIN orders ON customers.CustomerID = orders.CustomerID ORDER BY customers.CustomerName;
In the above example, the FULL OUTER JOIN will return all rows from both the customers
and orders
tables. If a customer has no orders or an order has no customer, the NULL value will be returned for the non-matching column. The result set will be sorted in ascending order by customer name.