{"id":218,"date":"2016-03-25T16:32:02","date_gmt":"2016-03-25T16:32:02","guid":{"rendered":"https:\/\/sqltutorial.org\/?page_id=218"},"modified":"2025-02-10T00:33:19","modified_gmt":"2025-02-10T07:33:19","slug":"sql-inner-join","status":"publish","type":"page","link":"https:\/\/www.sqltutorial.org\/sql-inner-join\/","title":{"rendered":"SQL INNER JOIN"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to use the SQL <code>INNER JOIN<\/code> clause to merge rows from two tables based on a condition.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='introduction-to-the-sql-inner-join-clause'>Introduction to the SQL INNER JOIN clause <a href=\"#introduction-to-the-sql-inner-join-clause\" class=\"anchor\" id=\"introduction-to-the-sql-inner-join-clause\" title=\"Anchor for Introduction to the SQL INNER JOIN clause\">#<\/a><\/h2>\n\n\n\n<p>The <code>INNER JOIN<\/code> is an optional clause of the <code><a href=\"https:\/\/www.sqltutorial.org\/sql-select\/\">SELECT<\/a><\/code> statement. The <code>INNER JOIN<\/code> clause allows you to merge rows from two related tables.<\/p>\n\n\n\n<p>Here&#8217;s the syntax of the <code>INNER JOIN<\/code> clause:<\/p>\n\n\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>\n  column1,\n  column2\n<span class=\"hljs-keyword\">FROM<\/span>\n  table1\n  <span class=\"hljs-keyword\">INNER<\/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\">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>In this syntax:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, specify the first table in the <code>FROM<\/code> clause (<code>table1<\/code>)<\/li>\n\n\n\n<li>Second, provide the second table you want to merge rows with the first table in the <code>INNER JOIN<\/code> clause (<code>table2<\/code>).<\/li>\n\n\n\n<li>Third, define a <code>condition<\/code> for matching rows between two tables after the <code>ON<\/code> keyword. This condition is known as a join condition.<\/li>\n<\/ul>\n\n\n\n<p>For each row in the <code>table1<\/code>, the <code>INNER JOIN<\/code> clause examines each row in the <code>table2<\/code> and checks the condition.<\/p>\n\n\n\n<p>If the <code>condition<\/code> is <code>true<\/code>, the <code>INNER JOIN<\/code> merges the rows from both tables to form a single row and includes it in the final result set.<\/p>\n\n\n\n<p>Typically, the condition compares values between two columns of the two tables for equality:<\/p>\n\n\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\">SELECT<\/span>\n  column1,\n  column2\n<span class=\"hljs-keyword\">FROM<\/span>\n  table1\n  <span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> table2 <span class=\"hljs-keyword\">ON<\/span> column1 = column2;<\/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>\n\n\n<p>However, the join condition can be any comparison operator, not just an equal operator (<code>=<\/code>).<\/p>\n\n\n\n<p>If the <code>INNER JOIN<\/code> requires multiple conditions, you can use the <code>AND<\/code> operator to combine them.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='understanding-sql-inner-join'>Understanding SQL inner join <a href=\"#understanding-sql-inner-join\" class=\"anchor\" id=\"understanding-sql-inner-join\" title=\"Anchor for Understanding SQL inner join\">#<\/a><\/h2>\n\n\n\n<p>Suppose you have two tables:<\/p>\n\n\n\n<ul 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=\"Y Table\" 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=\"X Table\" class=\"wp-image-3508\"\/><\/figure>\n<\/div><\/div>\n<\/div>\n\n\n\n<p>The inner join matches the rows between the <code>X<\/code> and <code>Y<\/code> tables using the values in the <code>id<\/code> columns.<\/p>\n\n\n\n<p>The inner join includes only the rows with matching values in the <code>id<\/code> columns and does not includes unmatching rows in the result set:<\/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-inner-join-visualization.svg\" alt=\"sql inner join visualization\" class=\"wp-image-3506\"\/><\/figure>\n<\/div>\n\n\n<p>The following Venn diagram is another way to illustrate an inner 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-inner-join-Venn-diagram.svg\" alt=\"sql inner join Venn diagram\" class=\"wp-image-3510\"\/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\" id='essential-sql-inner-join-example'>Essential SQL INNER JOIN example <a href=\"#essential-sql-inner-join-example\" class=\"anchor\" id=\"essential-sql-inner-join-example\" title=\"Anchor for Essential SQL INNER JOIN 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 has three columns <code>employee_id<\/code>, <code>name<\/code>, and <code>department_id<\/code>:<\/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 has two columns <code>department_id<\/code> and <code>department_name<\/code>:<\/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><\/tbody><\/table><\/figure>\n\n\n\n<p>The following statement uses an inner join to select data from the <code>employee_id<\/code> and <code>name<\/code> from the <code>employees<\/code> table and <code>department_name<\/code> from the <code>departments<\/code> tables:<\/p>\n\n\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\">SELECT<\/span>\n  employee_id,\n  <span class=\"hljs-type\">name<\/span>,\n  department_name\n<span class=\"hljs-keyword\">FROM<\/span>\n  employees\n  <span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> departments <span class=\"hljs-keyword\">ON<\/span> departments.department_id = employees.department_id;<\/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>\n\n\n<p><a href=\"https:\/\/www.sqltutorial.org\/playground\/?db=join&amp;q=U0VMRUNUIGVtcGxveWVlX2lkLCBuYW1lLCBkZXBhcnRtZW50X25hbWUgRlJPTSBlbXBsb3llZXMgSU5ORVIgSk9JTiBkZXBhcnRtZW50cyBPTiBkZXBhcnRtZW50cy5kZXBhcnRtZW50X2lkID0gZW1wbG95ZWVzLmVtcGxveWVlX2lkOw%3D%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-4\" 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<\/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>How the query works.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Step 1. The <code>FROM<\/code> clause returns all rows from the <code>employees<\/code> table.<\/li>\n\n\n\n<li>Step 2. The <code>INNER JOIN<\/code> compares values in the <code>department_id<\/code> column of the <code>employees<\/code> table with values in the <code>department_id<\/code> of the <code>departments<\/code> table. If they are equal, the <code>INNER JOIN<\/code> clause merge the rows from both tables into a single row.<\/li>\n\n\n\n<li>Step 3. The query return rows with columns specified in the <code>SELECT<\/code> clause.<\/li>\n<\/ul>\n\n\n\n<p>Here&#8217;s the break down of the inner join:<\/p>\n\n\n\n<p>The row #1 in the <code>employees<\/code> table (<code>department_id<\/code> 1) matches with the row #1 in the <code>departments<\/code> table (<code>department_id<\/code> 1):<\/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><\/tbody><\/table><\/figure>\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><\/tbody><\/table><\/figure>\n\n\n\n<p>The <code>INNER JOIN<\/code> clause merges the rows from both tables into a single row like this:<\/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 (<code>department_id<\/code> 2) matches with the row #2 in the <code>departments<\/code> table (<code>department_id<\/code> 2):<\/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>Bob<\/td><td>2<\/td><\/tr><\/tbody><\/table><\/figure>\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>2<\/td><td>Marketing<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The <code>INNER JOIN<\/code> merges the rows from both tables:<\/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 match with both rows #1 and # 2 in the <code>departments<\/code> table.<\/p>\n\n\n\n<p>After complete matching all the rows, the <code>INNER JOIN<\/code> comes up with the following intermediate result sets:<\/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><\/tbody><\/table><\/figure>\n\n\n\n<p>The <code>SELECT<\/code> clause retrieves the data from the <code>employee_id<\/code>, <code>name<\/code>, and <code>department_name<\/code> columns to form the following 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><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id='qualifying-column-names'>Qualifying column names <a href=\"#qualifying-column-names\" class=\"anchor\" id=\"qualifying-column-names\" title=\"Anchor for Qualifying column names\">#<\/a><\/h2>\n\n\n\n<p>The following attempts to include the <code>department_id<\/code> column in the result set:<\/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\"><span class=\"hljs-keyword\">SELECT<\/span>\n  employee_id,\n  <span class=\"hljs-type\">name<\/span>,\n  department_name,\n  department_id\n<span class=\"hljs-keyword\">FROM<\/span>\n  employees\n  <span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> departments <span class=\"hljs-keyword\">ON<\/span> departments.department_id = employees.department_id;<\/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>The database system issued the following error:<\/p>\n\n\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\">ERROR:  <span class=\"hljs-keyword\">column<\/span> reference \"department_id\" <span class=\"hljs-keyword\">is<\/span> ambiguous<\/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>\n\n\n<p>The reason is that both <code>employees<\/code> and <code>department<\/code> tables have the same <code>department_id<\/code> column. The database system does not know which one to select.<\/p>\n\n\n\n<p>To avoid this error, you need to explicitly tell the database system which table you want to retrieve the value from the <code>department_id<\/code> column.<\/p>\n\n\n\n<p>To do that, you can reference the column using the following syntax:<\/p>\n\n\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-built_in\">table_name<\/span>.<span class=\"hljs-built_in\">column_name<\/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>\n\n\n<p>For example:<\/p>\n\n\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>\n  employee_id,\n  <span class=\"hljs-type\">name<\/span>,\n  department_name,\n  employees.department_id\n<span class=\"hljs-keyword\">FROM<\/span>\n  employees\n  <span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> departments <span class=\"hljs-keyword\">ON<\/span> departments.department_id = employees.department_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>\n\n\n<p><a href=\"https:\/\/www.sqltutorial.org\/playground\/?db=join&amp;q=U0VMRUNUIGVtcGxveWVlX2lkLCBuYW1lLCBkZXBhcnRtZW50X25hbWUsIGVtcGxveWVlcy5kZXBhcnRtZW50X2lkIEZST00gZW1wbG95ZWVzIElOTkVSIEpPSU4gZGVwYXJ0bWVudHMgT04gZGVwYXJ0bWVudHMuZGVwYXJ0bWVudF9pZCA9IGVtcGxveWVlcy5kZXBhcnRtZW50X2lkOw%3D%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-9\" 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 | department_id\n<span class=\"hljs-comment\">-------------+------+-----------------+---------------<\/span>\n           <span class=\"hljs-number\">1<\/span> | Jane | Sales           |             <span class=\"hljs-number\">1<\/span>\n           <span class=\"hljs-number\">2<\/span> | Bob  | Marketing       |             <span class=\"hljs-number\">2<\/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>\n\n\n<p>In this example, we explicitly tell the database system to select data from the <code>department_id<\/code> column of the <code>employees<\/code> table:<\/p>\n\n\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\">employees.department_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>\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>SQL allows you to temporarily assign a new name to a table during the execution of a query. This new name is called a <strong>table alias<\/strong>.<\/p>\n\n\n\n<p>Here&#8217;s the syntax for defining a table alias:<\/p>\n\n\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-built_in\">table_name<\/span> <span class=\"hljs-keyword\">AS<\/span> table_alias<\/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>\n\n\n<p>The <code>AS<\/code> keyword is optional, so you can make it shorter like this:<\/p>\n\n\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-built_in\">table_name<\/span> table_alias<\/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>\n\n\n<p>When referencing a column, you can use the table alias instead of the table name:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">table_alias.<span class=\"hljs-built_in\">column_name<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><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>In practice, you often use the table alias when joining tables with the same column names. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" 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  e.department_id\n<span class=\"hljs-keyword\">FROM<\/span>\n  employees e\n  <span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> departments d <span class=\"hljs-keyword\">ON<\/span> d.department_id = e.department_id;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><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=join&amp;q=U0VMRUNUIGVtcGxveWVlX2lkLCBuYW1lLCBkZXBhcnRtZW50X25hbWUsIGUuZGVwYXJ0bWVudF9pZCBGUk9NIGVtcGxveWVlcyBlIElOTkVSIEpPSU4gZGVwYXJ0bWVudHMgZCBPTiBkLmRlcGFydG1lbnRfaWQgPSBlLmRlcGFydG1lbnRfaWQ7\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>In this example, we assign the table aliases:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>e<\/code> to the <code>employees<\/code> table.<\/li>\n\n\n\n<li><code>d<\/code> to the <code>departments<\/code> table.<\/li>\n<\/ul>\n\n\n\n<p>And reference the columns using the table aliases:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-15\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">d.department_id\ne.employee_id<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-15\"><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>The table aliases make the query more concise.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='joining-two-tables'>Joining two tables <a href=\"#joining-two-tables\" class=\"anchor\" id=\"joining-two-tables\" title=\"Anchor for Joining two tables\">#<\/a><\/h2>\n\n\n\n<p>The following example uses an inner join to merge rows from the <code>employees<\/code> and <code>departments<\/code> tables in the <a href=\"https:\/\/www.sqltutorial.org\/sql-sample-database\/\">sample database<\/a>:<\/p>\n\n\n\n<p class=\"note\">Note that these tables are different from the <code>employees<\/code> and <code>departments<\/code> above.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"451\" height=\"269\" src=\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/01\/employees_departments_tables.png\" alt=\"SQL INNER JOIN - Employees &amp; Departments Tables\" class=\"wp-image-1190\" srcset=\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/01\/employees_departments_tables.png 451w, https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/01\/employees_departments_tables-300x179.png 300w\" sizes=\"auto, (max-width: 451px) 100vw, 451px\" \/><\/figure>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-16\" 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  first_name,\n  last_name,\n  email,\n  department_name\n<span class=\"hljs-keyword\">FROM<\/span>\n  employees e\n  <span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> departments d <span class=\"hljs-keyword\">ON<\/span> d.department_id = e.department_id\n<span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span>\n  first_name,\n  last_name;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-16\"><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\/?q=U0VMRUNUIGZpcnN0X25hbWUsIGxhc3RfbmFtZSwgZW1haWwsIGRlcGFydG1lbnRfbmFtZSBGUk9NIGVtcGxveWVlcyBlIElOTkVSIEpPSU4gZGVwYXJ0bWVudHMgZCBPTiBkLmRlcGFydG1lbnRfaWQgPSBlLmRlcGFydG1lbnRfaWQgT1JERVIgQlkgZmlyc3RfbmFtZSwgbGFzdF9uYW1lOw%3D%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-17\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"> first_name  |  last_name  |               email               | department_name\n<span class=\"hljs-comment\">-------------+-------------+-----------------------------------+------------------<\/span>\n Adam        | Fripp       | adam.fripp@sqltutorial.org        | Shipping\n Alexander   | Hunold      | alexander.hunold@sqltutorial.org  | IT\n Alexander   | Khoo        | alexander.khoo@sqltutorial.org    | Purchasing\n Britney     | Everett     | britney.everett@sqltutorial.org   | Shipping\n Bruce       | Ernst       | bruce.ernst@sqltutorial.org       | IT\n...<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-17\"><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<h2 class=\"wp-block-heading\" id='joining-three-tables'>Joining three tables <a href=\"#joining-three-tables\" class=\"anchor\" id=\"joining-three-tables\" title=\"Anchor for Joining three tables\">#<\/a><\/h2>\n\n\n\n<p>To merge rows from more than two tables, you use additional <code>INNER JOIN<\/code> clauses. For example, here&#8217;s the syntax for joining three tables:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-18\" 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  column1,\n  column2,\n  column3\n<span class=\"hljs-keyword\">FROM<\/span>\n  table1\n  <span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> table2 <span class=\"hljs-keyword\">ON<\/span> condition1\n  <span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> table3 <span class=\"hljs-keyword\">ON<\/span> condition2;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-18\"><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 it works.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, the query matches every row from the <code>table1<\/code> with every row in the <code>table2<\/code> and <code>table3<\/code> based on the <code>condition1<\/code> and <code>condition2<\/code>. If the rows from the three tables meet both conditions, the <code>INNER JOIN<\/code> clauses merge rows from these tables into a single row.<\/li>\n\n\n\n<li>Then, the query selects columns from the merged rows and includes them in the result set.<\/li>\n<\/ul>\n\n\n\n<p>For example, the following query uses an <code>INNER JOIN<\/code> clause to merge rows from three tables <code>employees<\/code>, <code>departments<\/code>, and <code>jobs<\/code>: <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"729\" height=\"300\" src=\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2016\/03\/emp_dept_jobs_tables.png\" alt=\"SQL INNER JOIN - Joining three tables\" class=\"wp-image-229\" srcset=\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2016\/03\/emp_dept_jobs_tables.png 729w, https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2016\/03\/emp_dept_jobs_tables-300x123.png 300w\" sizes=\"auto, (max-width: 729px) 100vw, 729px\" \/><\/figure>\n\n\n\n<p>And select the first name, last name, job title, and department name of all employees:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-19\" 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  first_name,\n  last_name,\n  job_title,\n  department_name\n<span class=\"hljs-keyword\">FROM<\/span>\n  employees e\n  <span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> departments d <span class=\"hljs-keyword\">ON<\/span> d.department_id = e.department_id\n  <span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> jobs j <span class=\"hljs-keyword\">ON<\/span> j.job_id = e.job_id\n<span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span>\n  first_name,\n  last_name;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-19\"><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\/?q=U0VMRUNUIGZpcnN0X25hbWUsIGxhc3RfbmFtZSwgam9iX3RpdGxlLCBkZXBhcnRtZW50X25hbWUgRlJPTSBlbXBsb3llZXMgZSBJTk5FUiBKT0lOIGRlcGFydG1lbnRzIGQgT04gZC5kZXBhcnRtZW50X2lkID0gZS5kZXBhcnRtZW50X2lkIElOTkVSIEpPSU4gam9icyBqIE9OIGouam9iX2lkID0gZS5qb2JfaWQgT1JERVIgQlkgZmlyc3RfbmFtZSwgbGFzdF9uYW1lOw%3D%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-20\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"> first_name  |  last_name  |            job_title            | department_name\n<span class=\"hljs-comment\">-------------+-------------+---------------------------------+------------------<\/span>\n Adam        | Fripp       | Stock Manager                   | Shipping\n Alexander   | Hunold      | Programmer                      | IT\n Alexander   | Khoo        | Purchasing Clerk                | Purchasing\n Britney     | Everett     | Shipping Clerk                  | Shipping\n Bruce       | Ernst       | Programmer                      | IT\n...<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-20\"><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<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 SQL <code>INNER JOIN<\/code> clause to merge rows from two tables based on a condition.<\/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<iframe loading=\"lazy\"\n  name=\"quiz\"\n  src=\"\/quiz\/?quiz=inner-join\"\n  height=\"700\"\n  width=\"600\"\n  class=\"iframe\"\n><\/iframe>\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-inner-join\/\" target=\"_blank\" rel=\"noreferrer noopener\">PostgreSQL Inner Join<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.oracletutorial.com\/oracle-basics\/oracle-inner-join\/\" target=\"_blank\" rel=\"noreferrer noopener\">Oracle Inner Join<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-inner-join\/\" target=\"_blank\" rel=\"noreferrer noopener\">SQL Server Inner Join<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-inner-join\/\" target=\"_blank\" rel=\"noreferrer noopener\">MySQL Inner Join<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-inner-join\/\" target=\"_blank\" rel=\"noreferrer noopener\">SQLite Inner Join<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.db2tutorial.com\/db2-basics\/db2-inner-join\/\" target=\"_blank\" rel=\"noreferrer noopener\">Db2 Inner Join<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mariadbtutorial.com\/mariadb-basics\/mariadb-inner-join\/\" target=\"_blank\" rel=\"noreferrer noopener\">MariaDB Inner 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=\"218\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqltutorial.org\/sql-inner-join\/\"\n\t\t\t\tdata-post-title=\"SQL INNER 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=\"218\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqltutorial.org\/sql-inner-join\/\"\n\t\t\t\tdata-post-title=\"SQL INNER 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 SQL INNER JOIN clause to merge rows from two tables based on a condition.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":16,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-218","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 INNER JOIN<\/title>\n<meta name=\"description\" content=\"In this tutorial, you will learn how to use the SQL INNER JOIN clause to merge rows from two tables based on a condition.\" \/>\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-inner-join\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL INNER JOIN\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, you will learn how to use the SQL INNER JOIN clause to merge rows from two tables based on a condition.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqltutorial.org\/sql-inner-join\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-10T07:33:19+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=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqltutorial.org\/sql-inner-join\/\",\"url\":\"https:\/\/www.sqltutorial.org\/sql-inner-join\/\",\"name\":\"SQL INNER JOIN\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqltutorial.org\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.sqltutorial.org\/sql-inner-join\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.sqltutorial.org\/sql-inner-join\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2025\/02\/x-table.svg\",\"datePublished\":\"2016-03-25T16:32:02+00:00\",\"dateModified\":\"2025-02-10T07:33:19+00:00\",\"description\":\"In this tutorial, you will learn how to use the SQL INNER JOIN clause to merge rows from two tables based on a condition.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.sqltutorial.org\/sql-inner-join\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqltutorial.org\/sql-inner-join\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqltutorial.org\/sql-inner-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-inner-join\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqltutorial.org\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL INNER 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 INNER JOIN","description":"In this tutorial, you will learn how to use the SQL INNER JOIN clause to merge rows from two tables based on a condition.","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-inner-join\/","og_locale":"en_US","og_type":"article","og_title":"SQL INNER JOIN","og_description":"In this tutorial, you will learn how to use the SQL INNER JOIN clause to merge rows from two tables based on a condition.","og_url":"https:\/\/www.sqltutorial.org\/sql-inner-join\/","og_site_name":"SQL Tutorial","article_modified_time":"2025-02-10T07:33:19+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqltutorial.org\/sql-inner-join\/","url":"https:\/\/www.sqltutorial.org\/sql-inner-join\/","name":"SQL INNER JOIN","isPartOf":{"@id":"https:\/\/www.sqltutorial.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.sqltutorial.org\/sql-inner-join\/#primaryimage"},"image":{"@id":"https:\/\/www.sqltutorial.org\/sql-inner-join\/#primaryimage"},"thumbnailUrl":"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2025\/02\/x-table.svg","datePublished":"2016-03-25T16:32:02+00:00","dateModified":"2025-02-10T07:33:19+00:00","description":"In this tutorial, you will learn how to use the SQL INNER JOIN clause to merge rows from two tables based on a condition.","breadcrumb":{"@id":"https:\/\/www.sqltutorial.org\/sql-inner-join\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqltutorial.org\/sql-inner-join\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqltutorial.org\/sql-inner-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-inner-join\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqltutorial.org\/"},{"@type":"ListItem","position":2,"name":"SQL INNER 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\/218","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=218"}],"version-history":[{"count":0,"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/pages\/218\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/media?parent=218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}