full outer jion
时间: 2024-05-25 20:17:57 浏览: 31
A full outer join, also known as a full join, combines the results of a left outer join and a right outer join. It returns all rows from both tables, including those that do not have a match in the other table. If there is no match in one of the tables, the result will contain null values for the columns of that table.
For example, consider two tables: Customers and Orders. The Customers table has the following data:
| CustomerID | CustomerName |
|------------|--------------|
| 1 | John |
| 2 | Mary |
| 3 | Tom |
The Orders table has the following data:
| OrderID | CustomerID | OrderDate |
|---------|------------|-------------|
| 100 | 1 | 2021-01-01 |
| 101 | 2 | 2021-02-01 |
| 102 | 4 | 2021-03-01 |
A full outer join on the Customers and Orders tables would return the following result:
| CustomerID | CustomerName | OrderID | OrderDate |
|------------|--------------|---------|-------------|
| 1 | John | 100 | 2021-01-01 |
| 2 | Mary | 101 | 2021-02-01 |
| 3 | Tom | NULL | NULL |
| NULL | NULL | 102 | 2021-03-01 |
Note that the result contains all rows from both tables, even though there is no match for CustomerID 3 in the Orders table and no match for OrderID 102 in the Customers table. These rows have null values for the columns of the non-matching table.
阅读全文