100 Days of SQL

sql

Day 21 – SQL FULL OUTER JOIN Keyword

The SQL FULL OUTER JOIN keyword is used to combine rows from two or more tables, including all the rows from both tables, regardless of whether there is a matching row in the other table(s).

The syntax for a FULL OUTER JOIN is as follows:


SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name = table2.column_name;

In this syntax, table1 and table2 are the names of the tables that you want to join, and column_name is the name of the column that you want to join the tables on.

The result of a FULL OUTER JOIN is a table that contains all the rows from both tables, with NULL values in the columns where there is no matching row in the other table(s). If there is a matching row, the columns from both tables are combined into a single row in the result set.

Note that not all database management systems support the FULL OUTER JOIN keyword. In such cases, you can simulate a FULL OUTER JOIN using a combination of a LEFT OUTER JOIN and a RIGHT OUTER JOIN.