{"id":302,"date":"2024-11-25T15:02:17","date_gmt":"2024-11-25T08:02:17","guid":{"rendered":"https:\/\/www.pgtutorial.com\/?page_id=302"},"modified":"2025-02-10T14:54:58","modified_gmt":"2025-02-10T07:54:58","slug":"postgresql-left-join","status":"publish","type":"page","link":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-left-join\/","title":{"rendered":"PostgreSQL Left Join"},"content":{"rendered":"\r\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to use the PostgreSQL <code>LEFT JOIN<\/code> clause to merge rows of two tables.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id='introduction-to-postgresql-left-join-clause'>Introduction to PostgreSQL LEFT JOIN clause <a href=\"#introduction-to-postgresql-left-join-clause\" class=\"anchor\" id=\"introduction-to-postgresql-left-join-clause\" title=\"Anchor for Introduction to PostgreSQL LEFT JOIN clause\">#<\/a><\/h2>\r\n\r\n\r\n\r\n<p>The <code>LEFT JOIN<\/code> is an optional clause of the <code><a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-select\/\">SELECT<\/a><\/code> statement. The <code>LEFT JOIN<\/code> clause merges rows from two tables and returns all rows from the left table and matching rows from the right table.<\/p>\r\n\r\n\r\n\r\n<p>Here&#8217;s the syntax of the <code>LEFT JOIN<\/code> clause:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" 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>\r\n  left_table.column1,\r\n  right_table.column2,\r\n  ...\r\n<span class=\"hljs-keyword\">FROM<\/span>\r\n  left_table\r\n  <span class=\"hljs-keyword\">LEFT JOIN<\/span> right_table <span class=\"hljs-keyword\">ON<\/span> right_table.column1 = left_table.column1;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><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>\r\n\r\n\r\n<p>In this syntax:<\/p>\r\n\r\n\r\n\r\n<p>First, specify the name of the left table (<code>left_table<\/code>) in the\u00a0<code>FROM<\/code>\u00a0clause:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" 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\">FROM<\/span> left_table<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><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>\r\n\r\n\r\n<p>Second, provide the name of the right table (<code>right_table<\/code>) to join with the left table in the <code>LEFT JOIN<\/code>\u00a0clause:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" 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\">LEFT JOIN<\/span> right_table<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><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>\r\n\r\n\r\n<p>Third, use a condition to match the rows in the left table (<code>left_table<\/code>) with the rows in the right table (<code>right_table<\/code>) in the\u00a0<code>ON<\/code>\u00a0clause:<\/p>\r\n\r\n\r\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\">ON<\/span> left_table.column1 = right_table.column1;<\/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>\r\n\r\n\r\n<p>This condition matches rows by comparing the values of\u00a0<code>column1<\/code>\u00a0in\u00a0the left table (<code>left_table<\/code>)\u00a0with the values of\u00a0<code>column1<\/code>\u00a0in the right table (<code>right_table<\/code>):<\/p>\r\n\r\n\r\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\">right_table.column1 = left_table.column1;<\/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>\r\n\r\n\r\n<p>PostgreSQL always includes the row from the left table with the matching row from the right table.<\/p>\r\n\r\n\r\n\r\n<p>If a row from the left table does not have a matching row in the right table, PostgreSQL does the following:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>First, create a &#8220;fake&#8221; row with columns from the right table.<\/li>\r\n\r\n\r\n\r\n<li>Second, fill all the columns with <a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-not-null\/\">NULL<\/a>.<\/li>\r\n\r\n\r\n\r\n<li>Third, merge the &#8220;fake&#8221; row with the row from the left table.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p>Finally, return the columns specified in the\u00a0<code>SELECT<\/code>\u00a0clause:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" 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>\r\n  left_table.column1,\r\n  right_table.column2,\r\n  ...<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><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>\r\n\r\n\r\n<p>Note that the table you specify in the <code>FROM<\/code> clause is the <em>left table<\/em>, while the table you provide in the <code>LEFT JOIN<\/code> clause is the <em>right table<\/em>.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id='understanding-postgresql-left-join'>Understanding PostgreSQL left join <a href=\"#understanding-postgresql-left-join\" class=\"anchor\" id=\"understanding-postgresql-left-join\" title=\"Anchor for Understanding PostgreSQL left join\">#<\/a><\/h2>\r\n\r\n\r\n\r\n<p>Suppose you want to merge rows from <code>X<\/code> and <code>Y<\/code> tables using a left join:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>The <code>X<\/code> table has two columns: <code>id <\/code>(key) and <code>x<\/code>.<\/li>\r\n\r\n\r\n\r\n<li>The <code>Y<\/code> table has also has two columns: <code>id<\/code> (key) and <code>y<\/code>.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><div class=\"wp-block-image\">\r\n<figure class=\"alignright size-full\"><img decoding=\"async\" class=\"wp-image-1951\" src=\"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/02\/x-table.svg\" alt=\"PostgreSQL inner join: Left Table\" \/><\/figure>\r\n<\/div><\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><div class=\"wp-block-image\">\r\n<figure class=\"alignleft size-full\"><img decoding=\"async\" class=\"wp-image-1952\" src=\"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/02\/y-table.svg\" alt=\"PostgreSQL inner join: Right Table\" \/><\/figure>\r\n<\/div><\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<p>The left join\u00a0includes all rows from the left table (<code>X<\/code>) and matching rows from the right table (<code>Y<\/code>); if a row in the left table does not have a matching on the right table, the <code>LEFT JOIN<\/code> uses\u00a0<code>null<\/code>\u00a0for columns of the right table (<code>Y<\/code>):<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" class=\"wp-image-1959\" src=\"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/02\/postgresql-left-join-visualization.svg\" alt=\"PostgreSQL left join visualization\" \/><\/figure>\r\n\r\n\r\n\r\n<p>The following Venn diagram is another way to depict how a left join works:<\/p>\r\n\r\n\r\n<div class=\"wp-block-image\">\r\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" class=\"wp-image-1960\" src=\"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/02\/postgresql-left-join-Venn-diagram.svg\" alt=\"SQL LEFT JOIN\" \/><\/figure>\r\n<\/div>\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id='postgresql-left-join-clause-example'>PostgreSQL LEFT JOIN clause example <a href=\"#postgresql-left-join-clause-example\" class=\"anchor\" id=\"postgresql-left-join-clause-example\" title=\"Anchor for PostgreSQL LEFT JOIN clause example\">#<\/a><\/h2>\r\n\r\n\r\n\r\n<p>Let&#8217;s take an example of using the <code>LEFT JOIN<\/code> clause.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\" id='setting-up-sample-tables'>Setting up sample tables <a href=\"#setting-up-sample-tables\" class=\"anchor\" id=\"setting-up-sample-tables\" title=\"Anchor for Setting up sample tables\">#<\/a><\/h3>\r\n\r\n\r\n\r\n<p>Suppose we have two tables <code>brands<\/code> and <code>products<\/code>:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" 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\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> brands (\r\n  brand_id <span class=\"hljs-type\">INT<\/span> <span class=\"hljs-keyword\">GENERATED<\/span> <span class=\"hljs-keyword\">ALWAYS<\/span> <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">IDENTITY<\/span> <span class=\"hljs-keyword\">PRIMARY KEY<\/span>,\r\n  <span class=\"hljs-type\">name<\/span> <span class=\"hljs-type\">VARCHAR<\/span>(<span class=\"hljs-number\">255<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-keyword\">NULL<\/span>\r\n);\r\n\r\n<span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> products (\r\n  product_id <span class=\"hljs-type\">INT<\/span> <span class=\"hljs-keyword\">GENERATED<\/span> <span class=\"hljs-keyword\">ALWAYS<\/span> <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">IDENTITY<\/span> <span class=\"hljs-keyword\">PRIMARY KEY<\/span>,\r\n  <span class=\"hljs-type\">name<\/span> <span class=\"hljs-type\">VARCHAR<\/span>(<span class=\"hljs-number\">100<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-keyword\">NULL<\/span>,\r\n  price <span class=\"hljs-type\">DECIMAL<\/span>(<span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">2<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-keyword\">NULL<\/span>,\r\n  brand_id <span class=\"hljs-type\">INT<\/span>,\r\n  <span class=\"hljs-keyword\">FOREIGN KEY<\/span> (brand_id) <span class=\"hljs-keyword\">REFERENCES<\/span> brands (brand_id)\r\n);\r\n\r\n<span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span>\r\n  brands (<span class=\"hljs-type\">name<\/span>)\r\n<span class=\"hljs-keyword\">VALUES<\/span>\r\n  (<span class=\"hljs-string\">'Apple'<\/span>),\r\n  (<span class=\"hljs-string\">'Samsung'<\/span>),\r\n  (<span class=\"hljs-string\">'Google'<\/span>) \r\n<span class=\"hljs-keyword\">RETURNING<\/span> *;\r\n\r\n<span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span>\r\n  products (<span class=\"hljs-type\">name<\/span>, price, brand_id)\r\n<span class=\"hljs-keyword\">VALUES<\/span>\r\n  (<span class=\"hljs-string\">'iPhone 14 Pro'<\/span>, <span class=\"hljs-number\">999.99<\/span>, <span class=\"hljs-number\">1<\/span>),\r\n  (<span class=\"hljs-string\">'iPhone 15 Pro'<\/span>, <span class=\"hljs-number\">1199.99<\/span>, <span class=\"hljs-number\">1<\/span>),\r\n  (<span class=\"hljs-string\">'Galaxy S23 Ultra'<\/span>, <span class=\"hljs-number\">1149.47<\/span>, <span class=\"hljs-number\">2<\/span>),\r\n  (<span class=\"hljs-string\">'Oppo Find Flip'<\/span>, <span class=\"hljs-number\">499.99<\/span>, <span class=\"hljs-keyword\">NULL<\/span>) \r\n<span class=\"hljs-keyword\">RETURNING<\/span> *;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><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>\r\n\r\n\r\n<p>The\u00a0<code>products<\/code>\u00a0table has a foreign key column,\u00a0<code>brand_id<\/code>, which references the <code>brand_id<\/code>\u00a0<a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-primary-key\/\">primary key<\/a>\u00a0column of the\u00a0<code>brands<\/code>\u00a0table.<\/p>\r\n\r\n\r\n\r\n<p>The <code>brands<\/code> table:<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-table\">\r\n<table class=\"has-fixed-layout\">\r\n<thead>\r\n<tr>\r\n<th>brand_id<\/th>\r\n<th>name<\/th>\r\n<\/tr>\r\n<\/thead>\r\n<tbody>\r\n<tr>\r\n<td>1<\/td>\r\n<td>Apple<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>2<\/td>\r\n<td>Samsung<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>3<\/td>\r\n<td>Google<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n\r\n\r\n\r\n<p>The <code>products<\/code> table:<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-table\">\r\n<table class=\"has-fixed-layout\">\r\n<thead>\r\n<tr>\r\n<th>product_id<\/th>\r\n<th>name<\/th>\r\n<th>price<\/th>\r\n<th>brand_id<\/th>\r\n<\/tr>\r\n<\/thead>\r\n<tbody>\r\n<tr>\r\n<td>1<\/td>\r\n<td>iPhone 14 Pro<\/td>\r\n<td>999.99<\/td>\r\n<td>1<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>2<\/td>\r\n<td>iPhone 15 Pro<\/td>\r\n<td>1299.99<\/td>\r\n<td>1<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>3<\/td>\r\n<td>Galaxy S23 Ultra<\/td>\r\n<td>1149.47<\/td>\r\n<td>2<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>4<\/td>\r\n<td>Oppo Find Flip<\/td>\r\n<td>499.99<\/td>\r\n<td>NULL<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\" id='joining-tables-using-the-left-join-clause'>Joining tables using the LEFT JOIN clause <a href=\"#joining-tables-using-the-left-join-clause\" class=\"anchor\" id=\"joining-tables-using-the-left-join-clause\" title=\"Anchor for Joining tables using the LEFT JOIN clause\">#<\/a><\/h3>\r\n\r\n\r\n\r\n<p>The following statement uses the <code>LEFT JOIN<\/code> clause to select all rows from the <code>brands<\/code> table with the matching rows from the <code>products<\/code> table:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" 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>\r\n  brands.name brand_name,\r\n  products.name product_name,\r\n  products.price\r\n<span class=\"hljs-keyword\">FROM<\/span>\r\n  brands\r\n  <span class=\"hljs-keyword\">LEFT JOIN<\/span> products <span class=\"hljs-keyword\">ON<\/span> products.brand_id = brands.brand_id;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><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>\r\n\r\n\r\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?db=join&amp;q=U0VMRUNUIGJyYW5kcy5uYW1lIGJyYW5kX25hbWUsIHByb2R1Y3RzLm5hbWUgcHJvZHVjdF9uYW1lLCBwcm9kdWN0cy5wcmljZSBGUk9NIGJyYW5kcyBMRUZUIEpPSU4gcHJvZHVjdHMgT04gcHJvZHVjdHMuYnJhbmRfaWQgPSBicmFuZHMuYnJhbmRfaWQ7\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\r\n\r\n\r\n\r\n<p>Output:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"> brand_name |   product_name   |  price\r\n<span class=\"hljs-comment\">------------+------------------+---------<\/span>\r\n Apple      | iPhone <span class=\"hljs-number\">14<\/span> Pro    |  <span class=\"hljs-number\">999.99<\/span>\r\n Apple      | iPhone <span class=\"hljs-number\">15<\/span> Pro    | <span class=\"hljs-number\">1199.99<\/span>\r\n Samsung    | Galaxy S23 Ultra | <span class=\"hljs-number\">1149.47<\/span>\r\n Google     | <span class=\"hljs-keyword\">NULL<\/span>             |    <span class=\"hljs-keyword\">NULL<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><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>\r\n\r\n\r\n<p>How it works.<\/p>\r\n\r\n\r\n\r\n<p>First, the\u00a0<code>FROM<\/code>\u00a0clause examines each row in the <code>brands<\/code> table.<\/p>\r\n\r\n\r\n\r\n<p>Second, the\u00a0<code>LEFT JOIN<\/code> clause compares values in the <code>brand_id<\/code>\u00a0column of each row in the <code>brands<\/code> table with values in the <code>brand_id<\/code> column\u00a0of each row in the\u00a0<code>products<\/code>\u00a0table.<\/p>\r\n\r\n\r\n\r\n<p>If they are equal, PostgreSQL merges the rows from both tables. If they are not equal, PostgreSQL creates a new row with the columns from the left table and columns from the right table filled with <code>NULL<\/code>.<\/p>\r\n\r\n\r\n\r\n<p>The brand with id 1 matches two rows in the <code>products<\/code> table:<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-table\">\r\n<table class=\"has-fixed-layout\">\r\n<thead>\r\n<tr>\r\n<th>brand_id<\/th>\r\n<th>name<\/th>\r\n<th>product_id<\/th>\r\n<th>name<\/th>\r\n<th>price<\/th>\r\n<th>brand_id<\/th>\r\n<\/tr>\r\n<\/thead>\r\n<tbody>\r\n<tr>\r\n<td><strong>1<\/strong><\/td>\r\n<td>Apple<\/td>\r\n<td>1<\/td>\r\n<td>iPhone 14 Pro<\/td>\r\n<td>999.99<\/td>\r\n<td><strong>1<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td><strong>1<\/strong><\/td>\r\n<td>Apple<\/td>\r\n<td>2<\/td>\r\n<td>iPhone 15 Pro<\/td>\r\n<td>1299.99<\/td>\r\n<td><strong>1<\/strong><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n\r\n\r\n\r\n<p>The brand with id 2 matches one row in the <code>products<\/code> table:<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-table\">\r\n<table class=\"has-fixed-layout\">\r\n<thead>\r\n<tr>\r\n<th>brand_id<\/th>\r\n<th>name<\/th>\r\n<th>product_id<\/th>\r\n<th>name<\/th>\r\n<th>price<\/th>\r\n<th>brand_id<\/th>\r\n<\/tr>\r\n<\/thead>\r\n<tbody>\r\n<tr>\r\n<td><strong>2<\/strong><\/td>\r\n<td>Samsung<\/td>\r\n<td>3<\/td>\r\n<td>Galaxy S23 Ultra<\/td>\r\n<td>1149.47<\/td>\r\n<td><strong>2<\/strong><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n\r\n\r\n\r\n<p>The brand with id 3 does not match any row in the <code>products<\/code> table. PostgreSQL creates a fake row for all columns corresponding to columns in the <code>products<\/code> table, fills them with <a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-not-null\/\">NULL<\/a>, and merges with the row in the left table:<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-table\">\r\n<table class=\"has-fixed-layout\">\r\n<thead>\r\n<tr>\r\n<th>brand_id<\/th>\r\n<th>name<\/th>\r\n<th>product_id<\/th>\r\n<th>name<\/th>\r\n<th>price<\/th>\r\n<th>brand_id<\/th>\r\n<\/tr>\r\n<\/thead>\r\n<tbody>\r\n<tr>\r\n<td><strong>1<\/strong><\/td>\r\n<td>Apple<\/td>\r\n<td>1<\/td>\r\n<td>iPhone 14 Pro<\/td>\r\n<td>999.99<\/td>\r\n<td><strong>1<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td><strong>1<\/strong><\/td>\r\n<td>Apple<\/td>\r\n<td>2<\/td>\r\n<td>iPhone 15 Pro<\/td>\r\n<td>1299.99<\/td>\r\n<td><strong>1<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td><strong>2<\/strong><\/td>\r\n<td>Samsung<\/td>\r\n<td>3<\/td>\r\n<td>Galaxy S23 Ultra<\/td>\r\n<td>1149.47<\/td>\r\n<td><strong>2<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td>3<\/td>\r\n<td>Google<\/td>\r\n<td>NULL<\/td>\r\n<td>NULL<\/td>\r\n<td>NULL<\/td>\r\n<td>NULL<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n\r\n\r\n\r\n<p>After examining all rows in the <code>brands<\/code> and <code>products<\/code> table, PostgreSQL comes up with the following intermediate result:<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-table\">\r\n<table class=\"has-fixed-layout\">\r\n<thead>\r\n<tr>\r\n<th>brand_id<\/th>\r\n<th>name<\/th>\r\n<th>product_id<\/th>\r\n<th>name<\/th>\r\n<th>price<\/th>\r\n<th>brand_id<\/th>\r\n<\/tr>\r\n<\/thead>\r\n<tbody>\r\n<tr>\r\n<td><strong>1<\/strong><\/td>\r\n<td>Apple<\/td>\r\n<td>1<\/td>\r\n<td>iPhone 14 Pro<\/td>\r\n<td>999.99<\/td>\r\n<td><strong>1<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td><strong>1<\/strong><\/td>\r\n<td>Apple<\/td>\r\n<td>2<\/td>\r\n<td>iPhone 15 Pro<\/td>\r\n<td>1299.99<\/td>\r\n<td><strong>1<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td><strong>2<\/strong><\/td>\r\n<td>Samsung<\/td>\r\n<td>3<\/td>\r\n<td>Galaxy S23 Ultra<\/td>\r\n<td>1149.47<\/td>\r\n<td><strong>2<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td>3<\/td>\r\n<td>Google<\/td>\r\n<td>NULL<\/td>\r\n<td>NULL<\/td>\r\n<td>NULL<\/td>\r\n<td>NULL<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n\r\n\r\n\r\n<p>Third, return the columns specified in the <code>SELECT<\/code> statement and grant them the column aliases:<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-table\">\r\n<table class=\"has-fixed-layout\">\r\n<thead>\r\n<tr>\r\n<th>brand_name<\/th>\r\n<th>product_name<\/th>\r\n<th>price<\/th>\r\n<\/tr>\r\n<\/thead>\r\n<tbody>\r\n<tr>\r\n<td>Apple<\/td>\r\n<td>iPhone 14 Pro<\/td>\r\n<td>999.99<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>Apple<\/td>\r\n<td>iPhone 15 Pro<\/td>\r\n<td>1299.99<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>Samsung<\/td>\r\n<td>Galaxy S23 Ultra<\/td>\r\n<td>1149.47<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>Google<\/td>\r\n<td>NULL<\/td>\r\n<td>NULL<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id='left-joining-tables-with-table-aliases'>Left joining tables with table aliases <a href=\"#left-joining-tables-with-table-aliases\" class=\"anchor\" id=\"left-joining-tables-with-table-aliases\" title=\"Anchor for Left joining tables with table aliases\">#<\/a><\/h2>\r\n\r\n\r\n\r\n<p>A table alias is a temporary name you assign to a table during the query execution.<\/p>\r\n\r\n\r\n\r\n<p>The following statement uses table aliases for the <code>brands<\/code> and <code>products<\/code> tables:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" 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>\r\n  b.name <span class=\"hljs-keyword\">AS<\/span> brand_name,\r\n  p.name <span class=\"hljs-keyword\">AS<\/span> product_name,\r\n  p.price\r\n<span class=\"hljs-keyword\">FROM<\/span>\r\n  brands b\r\n  <span class=\"hljs-keyword\">LEFT JOIN<\/span> products p <span class=\"hljs-keyword\">ON<\/span> p.brand_id = b.brand_id;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><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>\r\n\r\n\r\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?db=join&amp;q=U0VMRUNUIGIubmFtZSBBUyBicmFuZF9uYW1lLCBwLm5hbWUgQVMgcHJvZHVjdF9uYW1lLCBwLnByaWNlIEZST00gYnJhbmRzIGIgTEVGVCBKT0lOIHByb2R1Y3RzIHAgT04gcC5icmFuZF9pZCA9IGIuYnJhbmRfaWQ7\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id='postgresql-left-join-clause-with-the-using-syntax'>PostgreSQL LEFT JOIN clause with the USING syntax <a href=\"#postgresql-left-join-clause-with-the-using-syntax\" class=\"anchor\" id=\"postgresql-left-join-clause-with-the-using-syntax\" title=\"Anchor for PostgreSQL LEFT JOIN clause with the USING syntax\">#<\/a><\/h2>\r\n\r\n\r\n\r\n<p>When joining two tables by comparing values from the same column names using the equal operator (<code>=<\/code>), you can use the\u00a0<code>USING<\/code>\u00a0clause syntax:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" 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>\r\n  left_table.column1,\r\n  right_table.column2\r\n<span class=\"hljs-keyword\">FROM<\/span>\r\n  left_table\r\n  <span class=\"hljs-keyword\">LEFT JOIN<\/span> right_table <span class=\"hljs-keyword\">USING<\/span> (column1);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><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>\r\n\r\n\r\n<p>We use the <code>USING<\/code> clause instead of the <code>ON<\/code> clause in the <code>LEFT JOIN<\/code> in this statement.<\/p>\r\n\r\n\r\n\r\n<p>The following example joins the <code>brands<\/code> table with the <code>products<\/code> table using the <code>LEFT JOIN<\/code> clause with the <code>USING<\/code> syntax:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" 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>\r\n  b.name brand_name\r\n  p.name product_name,\r\n  p.price\r\n<span class=\"hljs-keyword\">FROM<\/span>\r\n  brands b\r\n  <span class=\"hljs-keyword\">LEFT JOIN<\/span> products p <span class=\"hljs-keyword\">USING<\/span> (brand_id);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><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>\r\n\r\n\r\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?db=join&amp;q=U0VMRUNUIGIubmFtZSBicmFuZF9uYW1lLCBwLm5hbWUgcHJvZHVjdF9uYW1lLCBwLnByaWNlIEZST00gYnJhbmRzIGIgTEVGVCBKT0lOIHByb2R1Y3RzIHAgVVNJTkcgKGJyYW5kX2lkKTs\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Use the\u00a0<code>LEFT JOIN<\/code>\u00a0clause to merge rows from two tables and return all rows from the left table with the matching rows from the right table.<\/li>\r\n\r\n\r\n\r\n<li>Use the\u00a0<code>USING<\/code> syntax when left joining two tables using the same column name and equal operator.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id='quiz'>Quiz <a href=\"#quiz\" class=\"anchor\" id=\"quiz\" title=\"Anchor for Quiz\">#<\/a><\/h2>\r\n\r\n\r\n\r\n<p><iframe loading=\"lazy\" class=\"iframe\" src=\"\/quiz\/?quiz=left-join\" name=\"quiz\" width=\"600\" height=\"700\"><\/iframe><\/p>\r\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=\"302\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-left-join\/\"\n\t\t\t\tdata-post-title=\"PostgreSQL Left 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=\"302\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-left-join\/\"\n\t\t\t\tdata-post-title=\"PostgreSQL Left 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 the PostgreSQL LEFT JOIN clause to merge rows from two tables.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":13,"menu_order":23,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-302","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PostgreSQL LEFT JOIN Clause<\/title>\n<meta name=\"description\" content=\"In this tutorial, you will learn how to use the PostgreSQL LEFT JOIN clause to merge rows from two 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.pgtutorial.com\/postgresql-tutorial\/postgresql-left-join\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PostgreSQL LEFT JOIN Clause\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, you will learn how to use the PostgreSQL LEFT JOIN clause to merge rows from two tables.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-left-join\/\" \/>\n<meta property=\"og:site_name\" content=\"PostgreSQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-10T07:54:58+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.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-left-join\\\/\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-left-join\\\/\",\"name\":\"PostgreSQL LEFT JOIN Clause\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-left-join\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-left-join\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pgtutorial.com\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/x-table.svg\",\"datePublished\":\"2024-11-25T08:02:17+00:00\",\"dateModified\":\"2025-02-10T07:54:58+00:00\",\"description\":\"In this tutorial, you will learn how to use the PostgreSQL LEFT JOIN clause to merge rows from two tables.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-left-join\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-left-join\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-left-join\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/x-table.svg\",\"contentUrl\":\"https:\\\/\\\/www.pgtutorial.com\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/x-table.svg\",\"caption\":\"x table\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-left-join\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pgtutorial.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PostgreSQL Tutorial\",\"item\":\"https:\\\/\\\/www.pgtutorial.com\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"PostgreSQL Left Join\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/#website\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/\",\"name\":\"PostgreSQL Tutorial\",\"description\":\"Learn PostgreSQL from Scratch\",\"alternateName\":\"PostgreSQL\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pgtutorial.com\\\/?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":"PostgreSQL LEFT JOIN Clause","description":"In this tutorial, you will learn how to use the PostgreSQL LEFT JOIN clause to merge rows from two 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.pgtutorial.com\/postgresql-tutorial\/postgresql-left-join\/","og_locale":"en_US","og_type":"article","og_title":"PostgreSQL LEFT JOIN Clause","og_description":"In this tutorial, you will learn how to use the PostgreSQL LEFT JOIN clause to merge rows from two tables.","og_url":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-left-join\/","og_site_name":"PostgreSQL Tutorial","article_modified_time":"2025-02-10T07:54:58+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.pgtutorial.com\/postgresql-tutorial\/postgresql-left-join\/","url":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-left-join\/","name":"PostgreSQL LEFT JOIN Clause","isPartOf":{"@id":"https:\/\/www.pgtutorial.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-left-join\/#primaryimage"},"image":{"@id":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-left-join\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/02\/x-table.svg","datePublished":"2024-11-25T08:02:17+00:00","dateModified":"2025-02-10T07:54:58+00:00","description":"In this tutorial, you will learn how to use the PostgreSQL LEFT JOIN clause to merge rows from two tables.","breadcrumb":{"@id":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-left-join\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-left-join\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-left-join\/#primaryimage","url":"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/02\/x-table.svg","contentUrl":"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/02\/x-table.svg","caption":"x table"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-left-join\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pgtutorial.com\/"},{"@type":"ListItem","position":2,"name":"PostgreSQL Tutorial","item":"https:\/\/www.pgtutorial.com\/"},{"@type":"ListItem","position":3,"name":"PostgreSQL Left Join"}]},{"@type":"WebSite","@id":"https:\/\/www.pgtutorial.com\/#website","url":"https:\/\/www.pgtutorial.com\/","name":"PostgreSQL Tutorial","description":"Learn PostgreSQL from Scratch","alternateName":"PostgreSQL","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pgtutorial.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/302","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/comments?post=302"}],"version-history":[{"count":16,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/302\/revisions"}],"predecessor-version":[{"id":1976,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/302\/revisions\/1976"}],"up":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/13"}],"wp:attachment":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/media?parent=302"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}