{"id":785,"date":"2016-07-04T05:02:55","date_gmt":"2016-07-04T05:02:55","guid":{"rendered":"https:\/\/sqltutorial.org\/?page_id=785"},"modified":"2025-02-08T20:41:49","modified_gmt":"2025-02-09T03:41:49","slug":"sql-full-outer-join","status":"publish","type":"page","link":"https:\/\/www.sqltutorial.org\/sql-full-outer-join\/","title":{"rendered":"SQL FULL OUTER JOIN"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to use SQL <code>FULL OUTER JOIN<\/code> clause to merge rows from two tables.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='introduction-to-sql-full-outer-join-clause'>Introduction to SQL FULL OUTER JOIN clause <a href=\"#introduction-to-sql-full-outer-join-clause\" class=\"anchor\" id=\"introduction-to-sql-full-outer-join-clause\" title=\"Anchor for Introduction to SQL FULL OUTER JOIN clause\">#<\/a><\/h2>\n\n\n\n<p>The <code>FULL OUTER JOIN<\/code> is an optional clause of a <code><a href=\"https:\/\/www.sqltutorial.org\/sql-select\/\">SELECT<\/a><\/code> statement. The <code>FULL OUTER JOIN<\/code> clause allows you to merge rows between two tables.<\/p>\n\n\n\n<p>Here&#8217;s the syntax of the <code>FULL OUTER JOIN<\/code> clause:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  column1,\n  column2\n<span class=\"hljs-keyword\">FROM<\/span>\n  table1\n  <span class=\"hljs-keyword\">FULL<\/span> <span class=\"hljs-keyword\">OUTER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> table2 <span class=\"hljs-keyword\">ON<\/span> condition;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this syntax:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, provide the first table (<code>table1<\/code>) in the <code>FROM<\/code> clause.<\/li>\n\n\n\n<li>Second, specify the second table (<code>table2<\/code>) you want to join with the first table (<code>table1<\/code>) after the <code>FULL OUTER JOIN<\/code> keywords.<\/li>\n\n\n\n<li>Third, define a <code>condition<\/code> for matching rows between two tables. You can combine multiple conditions using the <code><a href=\"https:\/\/www.sqltutorial.org\/sql-and\/\">AND<\/a><\/code> and <code><a href=\"https:\/\/www.sqltutorial.org\/sql-or\/\">OR<\/a><\/code> operators.<\/li>\n<\/ul>\n\n\n\n<p>The <code>FULL OUTER JOIN<\/code> clause matches rows in the <code>table1<\/code> with rows in the <code>table2<\/code>.<\/p>\n\n\n\n<p>If they match, the <code>FULL OUTER JOIN<\/code> clause combines rows from both tables into a single row and includes it in the result set.<\/p>\n\n\n\n<p>If a row in a table does not have a matching row in another table, the <code>FULL OUTER JOIN<\/code> fills in <code>NULL<\/code> for columns of the row in the missing table.<\/p>\n\n\n\n<p>Technically, a <code>FULL OUTER JOIN<\/code> is a combination of a <code><a href=\"https:\/\/www.sqltutorial.org\/sql-left-join\/\">LEFT JOIN<\/a><\/code> and a <code><a href=\"https:\/\/www.sqltutorial.org\/sql-right-join\/\">RIGHT JOIN<\/a><\/code>. If your database system does not support the <code>FULL OUTER JOIN<\/code> clause but the <code>LEFT JOIN<\/code> and <code>RIGHT JOIN<\/code>, you can emulate the <code>FULL OUTER JOIN<\/code> using the <code>LEFT JOIN<\/code> and <code>RIGHT JOIN<\/code> .<\/p>\n\n\n\n<p>Since the <code>OUTER<\/code> keyword is optional, you can omit it in the query like this:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  column1,\n  column2\n<span class=\"hljs-keyword\">FROM<\/span>\n  table1\n  <span class=\"hljs-keyword\">FULL<\/span> <span class=\"hljs-keyword\">JOIN<\/span> table2 <span class=\"hljs-keyword\">ON<\/span> condition;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Typically, you match rows between two tables by comparing the values of a common column using the equality operator (<code>=<\/code>). The <code>condition<\/code> in the <code>FULL JOIN<\/code> clause will be like this:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  column1,\n  column2\n<span class=\"hljs-keyword\">FROM<\/span>\n  table1\n  <span class=\"hljs-keyword\">FULL<\/span> <span class=\"hljs-keyword\">JOIN<\/span> table2 <span class=\"hljs-keyword\">ON<\/span> table2.column2 = table1.column1;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id=\"block-f7f56e6d-4069-4ee3-81ba-5a42ce92e924\" id='understanding-sql-full-outer-join'>Understanding SQL full outer join <a href=\"#understanding-sql-full-outer-join\" class=\"anchor\" id=\"understanding-sql-full-outer-join\" title=\"Anchor for Understanding SQL full outer join\">#<\/a><\/h2>\n\n\n\n<p id=\"block-2adc1140-abf4-4344-b894-dac981fdd64f\">Suppose you have two tables:<\/p>\n\n\n\n<ul id=\"block-9fd2e954-152a-4846-a911-93f3ff8efdb1\" class=\"wp-block-list\">\n<li>The <code>X<\/code> table has two columns <code>id <\/code>(key) and <code>x<\/code>.<\/li>\n\n\n\n<li>The <code>Y<\/code> table has also has two columns <code>id<\/code> (key) and <code>y<\/code>.<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><div class=\"wp-block-image\">\n<figure class=\"alignright size-full\"><img decoding=\"async\" src=\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2025\/02\/x-table.svg\" alt=\"\" class=\"wp-image-3507\"\/><\/figure>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><div class=\"wp-block-image\">\n<figure class=\"alignleft size-full\"><img decoding=\"async\" src=\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2025\/02\/y-table.svg\" alt=\"\" class=\"wp-image-3508\"\/><\/figure>\n<\/div><\/div>\n<\/div>\n\n\n\n<p id=\"block-9f22c9a8-3a5a-45f4-bbd4-c5573ec6182b\">The full outer join matches the rows between the tables <code>X<\/code> and <code>Y<\/code> using the values in the <code>id<\/code> columns of both tables.<\/p>\n\n\n\n<p id=\"block-e698eab9-89e2-480e-9ccb-32a4be3f397d\">The full outer join includes rows from both tables whether or not the rows have matching rows from another table. It uses <code>null<\/code> for columns of rows in the table that do not have matching rows in another table:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2025\/02\/sql-full-join-visualization.svg\" alt=\"sql full join visualization\" class=\"wp-image-3524\"\/><\/figure>\n<\/div>\n\n\n<p id=\"block-a5bd51df-39ae-4372-a961-176cb891c1ee\">The following Venn diagram is another way to illustrate a full outer join:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2025\/02\/sql-full-outer-join-Venn-diagram.svg\" alt=\"sql full outer join Venn diagram\" class=\"wp-image-3525\"\/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\" id='sql-full-outer-join-clause-example'>SQL FULL OUTER JOIN clause example <a href=\"#sql-full-outer-join-clause-example\" class=\"anchor\" id=\"sql-full-outer-join-clause-example\" title=\"Anchor for SQL FULL OUTER JOIN clause example\">#<\/a><\/h2>\n\n\n\n<p>Suppose we have two tables <code>employees<\/code> and <code>departments<\/code>.<\/p>\n\n\n\n<p>The <code>employees<\/code> table:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>employee_id<\/th><th>name<\/th><th>department_id<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>Jane<\/td><td>1<\/td><\/tr><tr><td>2<\/td><td>Bob<\/td><td>2<\/td><\/tr><tr><td>3<\/td><td>Maria<\/td><td>NULL<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The <code>departments<\/code> table:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>department_id<\/th><th>department_name<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>Sales<\/td><\/tr><tr><td>2<\/td><td>Marketing<\/td><\/tr><tr><td>3<\/td><td>HR<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The following query uses the <code>FULL OUTER JOIN<\/code> clause to retrieve the employee ID, name, and department name from the <code>employees<\/code> and <code>departments<\/code> tables:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  employee_id,\n  <span class=\"hljs-type\">name<\/span>,\n  department_name\n<span class=\"hljs-keyword\">FROM<\/span>\n  departments\n  <span class=\"hljs-keyword\">FULL<\/span> <span class=\"hljs-keyword\">OUTER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> employees <span class=\"hljs-keyword\">ON<\/span> employees.department_id = departments.department_id;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.sqltutorial.org\/playground\/?db=joins&amp;q=U0VMRUNUIGVtcGxveWVlX2lkLCBuYW1lLCBkZXBhcnRtZW50X25hbWUgRlJPTSBkZXBhcnRtZW50cyBGVUxMIE9VVEVSIEpPSU4gZW1wbG95ZWVzIE9OIGVtcGxveWVlcy5kZXBhcnRtZW50X2lkID0gZGVwYXJ0bWVudHMuZGVwYXJ0bWVudF9pZDs%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"> employee_id | <span class=\"hljs-type\">name<\/span>  | department_name\n<span class=\"hljs-comment\">-------------+-------+-----------------<\/span>\n           <span class=\"hljs-number\">1<\/span> | Jane  | Sales\n           <span class=\"hljs-number\">2<\/span> | Bob   | Marketing\n           <span class=\"hljs-number\">3<\/span> | Maria | <span class=\"hljs-keyword\">NULL<\/span>\n        <span class=\"hljs-keyword\">NULL<\/span> | <span class=\"hljs-keyword\">NULL<\/span>  | HR<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>How the query works:<\/p>\n\n\n\n<p>The row #1 in the <code>employees<\/code> table matches with row #1 in the <code>departments<\/code> table, the <code>FULL OUTER JOIN<\/code> merges them into a single row:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>employee_id<\/th><th>name<\/th><th>department_id<\/th><th>department_id<\/th><th>department_name<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>Jane<\/td><td>1<\/td><td>1<\/td><td>Sales<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The row #2 in the <code>employees<\/code> table matches with row #2 in the <code>departments<\/code> table, the <code>FULL OUTER JOIN<\/code> merges them into a single row:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>employee_id<\/th><th>name<\/th><th>department_id<\/th><th>department_id<\/th><th>department_name<\/th><\/tr><\/thead><tbody><tr><td>2<\/td><td>Bob<\/td><td>2<\/td><td>2<\/td><td>Marketing<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The row #3 in the <code>employees<\/code> table does not have matching rows in the <code>departments<\/code> table, the <code>FULL OUTER JOIN<\/code> clause fills in <code>NULL<\/code> for columns of the row from the <code>departments<\/code> table:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>employee_id<\/th><th>name<\/th><th>department_id<\/th><th>department_id<\/th><th>department_name<\/th><\/tr><\/thead><tbody><tr><td>3<\/td><td>Maria<\/td><td>NULL<\/td><td>NULL<\/td><td>NULL<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The row #3 in the <code>departemnts<\/code> table does not have a matching row in the <code>employees<\/code> table, the <code>FULL OUTER JOIN<\/code> clause fills in <code>NULL<\/code> for columns of the row from the <code>employees<\/code> table:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>employee_id<\/th><th>name<\/th><th>department_id<\/th><th>department_id<\/th><th>department_name<\/th><\/tr><\/thead><tbody><tr><td>NULL<\/td><td>NULL<\/td><td>NULL<\/td><td>3<\/td><td>HR<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>After matching all rows from both tables, the <code>FULL OUTER JOIN<\/code> comes up with the following intermediate result:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>employee_id<\/th><th>name<\/th><th>department_id<\/th><th>department_id<\/th><th>department_name<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>Jane<\/td><td>1<\/td><td>1<\/td><td>Sales<\/td><\/tr><tr><td>2<\/td><td>Bob<\/td><td>2<\/td><td>2<\/td><td>Marketing<\/td><\/tr><tr><td>3<\/td><td>Maria<\/td><td>NULL<\/td><td>NULL<\/td><td>NULL<\/td><\/tr><tr><td>NULL<\/td><td>NULL<\/td><td>NULL<\/td><td>3<\/td><td>HR<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The <code>SELECT<\/code> clause retrieves the <code>employee_id<\/code>, <code>name<\/code>, and <code>department_id<\/code> from the intermediate result set and returns the final result set:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>employee_id<\/th><th>name<\/th><th>department_name<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>Jane<\/td><td>Sales<\/td><\/tr><tr><td>2<\/td><td>Bob<\/td><td>Marketing<\/td><\/tr><tr><td>3<\/td><td>Maria<\/td><td>NULL<\/td><\/tr><tr><td>NULL<\/td><td>NULL<\/td><td>HR<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id='using-table-aliases'>Using table aliases <a href=\"#using-table-aliases\" class=\"anchor\" id=\"using-table-aliases\" title=\"Anchor for Using table aliases\">#<\/a><\/h2>\n\n\n\n<p>To make the query more concise, you can utilize table aliases in the query that uses the <code>FULL OUTER JOIN<\/code> clause. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  employee_id,\n  <span class=\"hljs-keyword\">name<\/span>,\n  department_name\n<span class=\"hljs-keyword\">FROM<\/span>\n  departments d\n  <span class=\"hljs-keyword\">FULL<\/span> <span class=\"hljs-keyword\">OUTER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> employees e <span class=\"hljs-keyword\">ON<\/span> e.department_id = d.department_id;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.sqltutorial.org\/playground\/?db=joins&amp;q=U0VMRUNUIGVtcGxveWVlX2lkLCBuYW1lLCBkZXBhcnRtZW50X25hbWUgRlJPTSBkZXBhcnRtZW50cyBkIEZVTEwgT1VURVIgSk9JTiBlbXBsb3llZXMgZSBPTiBlLmRlcGFydG1lbnRfaWQgPSBkLmRlcGFydG1lbnRfaWQ7\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>In this example:<\/p>\n\n\n\n<p>First, assign table aliases:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>d<\/code> to departments table<\/li>\n\n\n\n<li><code>e<\/code> to employees table.<\/li>\n<\/ul>\n\n\n\n<p>Then, use these aliases for referencing the <code>department_id<\/code> column.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='finding-non-matching-rows-from-both-tables'>Finding non-matching rows from both tables <a href=\"#finding-non-matching-rows-from-both-tables\" class=\"anchor\" id=\"finding-non-matching-rows-from-both-tables\" title=\"Anchor for Finding non-matching rows from both tables\">#<\/a><\/h2>\n\n\n\n<p>The <code>FULL OUTER JOIN<\/code> clause can help you find non-matching rows from two tables.<\/p>\n\n\n\n<p>For example, the following query uses the <code>FULL OUTER JOIN<\/code> clause to retrieve the rows in the <code>employees<\/code> table that does not have matching rows in the <code>departments<\/code> table and vice versa:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  employee_id,\n  <span class=\"hljs-keyword\">name<\/span>,\n  department_name\n<span class=\"hljs-keyword\">FROM<\/span>\n  departments d\n  <span class=\"hljs-keyword\">FULL<\/span> <span class=\"hljs-keyword\">OUTER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> employees e <span class=\"hljs-keyword\">ON<\/span> e.department_id = d.department_id\n<span class=\"hljs-keyword\">WHERE<\/span>\n  department_name <span class=\"hljs-keyword\">IS<\/span> <span class=\"hljs-literal\">NULL<\/span>\n  <span class=\"hljs-keyword\">OR<\/span> employee_id <span class=\"hljs-keyword\">IS<\/span> <span class=\"hljs-literal\">NULL<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.sqltutorial.org\/playground\/?db=joins&amp;q=U0VMRUNUIGVtcGxveWVlX2lkLCBuYW1lLCBkZXBhcnRtZW50X25hbWUgRlJPTSBkZXBhcnRtZW50cyBkIEZVTEwgT1VURVIgSk9JTiBlbXBsb3llZXMgZSBPTiBlLmRlcGFydG1lbnRfaWQgPSBkLmRlcGFydG1lbnRfaWQgV0hFUkUgZGVwYXJ0bWVudF9uYW1lIElTIE5VTEwgT1IgZW1wbG95ZWVfaWQgSVMgTlVMTDs%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"> employee_id | name  | department_name\n<span class=\"hljs-comment\">-------------+-------+-----------------<\/span>\n           3 | Maria | NULL\n        NULL | NULL  | HR<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The output indicates that employee ID 3 does not belong to any department, and the HR department has no employees.<\/p>\n\n\n\n<p>This query pattern can help examine data in the tables.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use the <code>FULL OUTER JOIN<\/code> clause to merge rows from two tables by including rows from both tables whether or not the rows have matching rows from another table.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id='quiz'>Quiz <a href=\"#quiz\" class=\"anchor\" id=\"quiz\" title=\"Anchor for Quiz\">#<\/a><\/h2>\n\n\n\n<p><iframe loading=\"lazy\" class=\"iframe\" src=\"\/quiz\/?quiz=full-join\" name=\"quiz\" width=\"600\" height=\"700\"><\/iframe><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='databases'>Databases <a href=\"#databases\" class=\"anchor\" id=\"databases\" title=\"Anchor for Databases\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-full-join\/\" target=\"_blank\" rel=\"noreferrer noopener\">PostgreSQL Full Join<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.oracletutorial.com\/oracle-basics\/oracle-full-outer-join\/\" target=\"_blank\" rel=\"noreferrer noopener\">Oracle Full Join<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-full-outer-join\/\" target=\"_blank\" rel=\"noreferrer noopener\">SQL Server Full Join<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-full-outer-join\/\" target=\"_blank\" rel=\"noreferrer noopener\">SQLite Full Join<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.db2tutorial.com\/db2-basics\/db2-full-outer-join\/\" target=\"_blank\" rel=\"noreferrer noopener\">Db2 Full Join<\/a><\/li>\n<\/ul>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful ?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"785\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqltutorial.org\/sql-full-outer-join\/\"\n\t\t\t\tdata-post-title=\"SQL FULL OUTER JOIN\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"785\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqltutorial.org\/sql-full-outer-join\/\"\n\t\t\t\tdata-post-title=\"SQL FULL OUTER JOIN\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you will learn how to use SQL FULL OUTER JOIN clause to merge rows from two tables.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":19,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-785","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>SQL FULL OUTER JOIN<\/title>\n<meta name=\"description\" content=\"Learn to use the SQL FULL OUTER JOIN clause to merge rows from two tables and return matching and non-matching rows from both tables.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqltutorial.org\/sql-full-outer-join\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL FULL OUTER JOIN\" \/>\n<meta property=\"og:description\" content=\"Learn to use the SQL FULL OUTER JOIN clause to merge rows from two tables and return matching and non-matching rows from both tables.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqltutorial.org\/sql-full-outer-join\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-09T03:41:49+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqltutorial.org\/sql-full-outer-join\/\",\"url\":\"https:\/\/www.sqltutorial.org\/sql-full-outer-join\/\",\"name\":\"SQL FULL OUTER JOIN\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqltutorial.org\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.sqltutorial.org\/sql-full-outer-join\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.sqltutorial.org\/sql-full-outer-join\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2025\/02\/x-table.svg\",\"datePublished\":\"2016-07-04T05:02:55+00:00\",\"dateModified\":\"2025-02-09T03:41:49+00:00\",\"description\":\"Learn to use the SQL FULL OUTER JOIN clause to merge rows from two tables and return matching and non-matching rows from both tables.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.sqltutorial.org\/sql-full-outer-join\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqltutorial.org\/sql-full-outer-join\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqltutorial.org\/sql-full-outer-join\/#primaryimage\",\"url\":\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2025\/02\/x-table.svg\",\"contentUrl\":\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2025\/02\/x-table.svg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqltutorial.org\/sql-full-outer-join\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqltutorial.org\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL FULL OUTER JOIN\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqltutorial.org\/#website\",\"url\":\"https:\/\/www.sqltutorial.org\/\",\"name\":\"SQL Tutorial\",\"description\":\"An Interactive SQL Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqltutorial.org\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQL FULL OUTER JOIN","description":"Learn to use the SQL FULL OUTER JOIN clause to merge rows from two tables and return matching and non-matching rows from both tables.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqltutorial.org\/sql-full-outer-join\/","og_locale":"en_US","og_type":"article","og_title":"SQL FULL OUTER JOIN","og_description":"Learn to use the SQL FULL OUTER JOIN clause to merge rows from two tables and return matching and non-matching rows from both tables.","og_url":"https:\/\/www.sqltutorial.org\/sql-full-outer-join\/","og_site_name":"SQL Tutorial","article_modified_time":"2025-02-09T03:41:49+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqltutorial.org\/sql-full-outer-join\/","url":"https:\/\/www.sqltutorial.org\/sql-full-outer-join\/","name":"SQL FULL OUTER JOIN","isPartOf":{"@id":"https:\/\/www.sqltutorial.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.sqltutorial.org\/sql-full-outer-join\/#primaryimage"},"image":{"@id":"https:\/\/www.sqltutorial.org\/sql-full-outer-join\/#primaryimage"},"thumbnailUrl":"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2025\/02\/x-table.svg","datePublished":"2016-07-04T05:02:55+00:00","dateModified":"2025-02-09T03:41:49+00:00","description":"Learn to use the SQL FULL OUTER JOIN clause to merge rows from two tables and return matching and non-matching rows from both tables.","breadcrumb":{"@id":"https:\/\/www.sqltutorial.org\/sql-full-outer-join\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqltutorial.org\/sql-full-outer-join\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqltutorial.org\/sql-full-outer-join\/#primaryimage","url":"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2025\/02\/x-table.svg","contentUrl":"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2025\/02\/x-table.svg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqltutorial.org\/sql-full-outer-join\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqltutorial.org\/"},{"@type":"ListItem","position":2,"name":"SQL FULL OUTER JOIN"}]},{"@type":"WebSite","@id":"https:\/\/www.sqltutorial.org\/#website","url":"https:\/\/www.sqltutorial.org\/","name":"SQL Tutorial","description":"An Interactive SQL Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqltutorial.org\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/pages\/785","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/comments?post=785"}],"version-history":[{"count":0,"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/pages\/785\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/media?parent=785"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}