The SQL FULL JOIN, also known as FULL OUTER JOIN, retrieves all records from both tables (table1 and table2), and where there is no match, the result set will contain NULL values for the columns from the other table.
Consider two tables, Orders and Customers, with columns as follows:
- Orders: OrderID, CustomerID,
OrderDate
- Customers: CustomerID,
CustomerName, City
We want to retrieve all orders and customers, including unmatched records
from both tables.
SELECT Orders.OrderID,
Orders.OrderDate, Customers.CustomerName, Customers.City FROM Orders FULL JOIN Customers ON
Orders.CustomerID = Customers.CustomerID;
In this example, the FULL JOIN retrieves all records from
both the Orders
and Customers
tables. If there is
no match for an order in the Customers
table, or a customer in the Orders
table, NULL values will be returned for the respective columns. This ensures
that all orders and customers are included in the result set, regardless of
whether they have corresponding records in the other table.
Comments
Post a Comment