{"id":6351,"date":"2017-07-15T08:20:59","date_gmt":"2017-07-15T15:20:59","guid":{"rendered":"http:\/\/www.mysqltutorial.org\/?page_id=6351"},"modified":"2024-01-05T01:33:21","modified_gmt":"2024-01-05T08:33:21","slug":"mysql-join","status":"publish","type":"page","link":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-join\/","title":{"rendered":"MySQL Join"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn various MySQL join clauses in the <code>SELECT<\/code> statement to query data from two tables.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction to MySQL join clauses<\/h2>\n\n\n\n<p>A relational database consists of multiple related tables linking together using common columns, which are known as <a href=\"http:\/www.mysqltutorial.org\/mysql-foreign-key\/\">foreign key<\/a> columns. Because of this, the data in each table is incomplete from the business perspective.<\/p>\n\n\n\n<p>For example, in the <a href=\"http:\/www.mysqltutorial.org\/getting-started-with-mysql\/mysql-sample-database\/\">sample database<\/a>, we have the <code>orders<\/code> and&nbsp;<code>orderdetails<\/code> tables that are linked using the <code>orderNumber<\/code> column:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"444\" height=\"194\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2009\/12\/orders_order_details_tables.png\" alt=\"MySQL Transaction: orders &amp; orderDetails Tables\" class=\"wp-image-3827\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2009\/12\/orders_order_details_tables.png 444w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2009\/12\/orders_order_details_tables-300x131.png 300w\" sizes=\"auto, (max-width: 444px) 100vw, 444px\" \/><\/figure>\n\n\n\n<p>To get complete order information, you need to query data from both <code>orders<\/code> and &nbsp;<code>orderdetails<\/code> tables.<\/p>\n\n\n\n<p>That&#8217;s why joins come into the play.<\/p>\n\n\n\n<p>A join is a method of linking data between one (<a href=\"http:\/www.mysqltutorial.org\/mysql-self-join\/\">self-join<\/a>) or more tables based on the values of the common column between the tables.<\/p>\n\n\n\n<p>MySQL supports the following types of joins:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-inner-join\/\">Inner join<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-left-join\/\">Left join<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-right-join\/\">Right join<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-cross-join\/\">Cross join<\/a><\/li>\n<\/ol>\n\n\n\n<p>To join tables, you use the cross join, inner join, left join, or right join clause. The join clause&nbsp;is used in the <code><a href=\"http:\/www.mysqltutorial.org\/mysql-basics\/mysql-select-from\/\">SELECT<\/a><\/code> statement appeared after the <code>FROM<\/code> clause.<\/p>\n\n\n\n<p>Note that MySQL hasn&#8217;t supported the <code>FULL OUTER JOIN<\/code> yet.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Setting up sample tables<\/h2>\n\n\n\n<p>First, <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-create-table\/\">create two tables<\/a> called <code>members<\/code> and <code>committees<\/code>:<\/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\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> members (\n    member_id <span class=\"hljs-built_in\">INT<\/span> AUTO_INCREMENT,\n    <span class=\"hljs-keyword\">name<\/span> <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">100<\/span>),\n    PRIMARY <span class=\"hljs-keyword\">KEY<\/span> (member_id)\n);\n\n<span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> committees (\n    committee_id <span class=\"hljs-built_in\">INT<\/span> AUTO_INCREMENT,\n    <span class=\"hljs-keyword\">name<\/span> <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">100<\/span>),\n    PRIMARY <span class=\"hljs-keyword\">KEY<\/span> (committee_id)\n);<\/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>Second, <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-insert\/\">insert<\/a> some rows into the tables <code>members<\/code> and <code>committees<\/code> :<\/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\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span> members(<span class=\"hljs-keyword\">name<\/span>)\n<span class=\"hljs-keyword\">VALUES<\/span>(<span class=\"hljs-string\">'John'<\/span>),(<span class=\"hljs-string\">'Jane'<\/span>),(<span class=\"hljs-string\">'Mary'<\/span>),(<span class=\"hljs-string\">'David'<\/span>),(<span class=\"hljs-string\">'Amelia'<\/span>);\n\n<span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span> committees(<span class=\"hljs-keyword\">name<\/span>)\n<span class=\"hljs-keyword\">VALUES<\/span>(<span class=\"hljs-string\">'John'<\/span>),(<span class=\"hljs-string\">'Mary'<\/span>),(<span class=\"hljs-string\">'Amelia'<\/span>),(<span class=\"hljs-string\">'Joe'<\/span>);<\/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>Third, <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-select-from\/\">query data<\/a> from the tables <code>members<\/code> and <code>committees<\/code>:<\/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> * <span class=\"hljs-keyword\">FROM<\/span> members;<\/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<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"plaintext\" data-shcb-language-slug=\"plaintext\"><span><code class=\"hljs language-plaintext\">+-----------+--------+\n| member_id | name   |\n+-----------+--------+\n|         1 | John   |\n|         2 | Jane   |\n|         3 | Mary   |\n|         4 | David  |\n|         5 | Amelia |\n+-----------+--------+\n5 rows in set (0.00 sec)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">plaintext<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">plaintext<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" 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> * <span class=\"hljs-keyword\">FROM<\/span> committees;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><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<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"plaintext\" data-shcb-language-slug=\"plaintext\"><span><code class=\"hljs language-plaintext\">+--------------+--------+\n| committee_id | name   |\n+--------------+--------+\n|            1 | John   |\n|            2 | Mary   |\n|            3 | Amelia |\n|            4 | Joe    |\n+--------------+--------+\n4 rows in set (0.00 sec)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">plaintext<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">plaintext<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Some members are committee members, and some are not. On the other hand, some committee members are in the <code>members<\/code> table, some are not.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">MySQL INNER JOIN clause<\/h2>\n\n\n\n<p>The following shows the basic syntax of the inner join clause that joins two tables <code>table_1<\/code> and <code>table_2<\/code>:<\/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> column_list\n<span class=\"hljs-keyword\">FROM<\/span> table_1\n<span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> table_2 <span class=\"hljs-keyword\">ON<\/span> join_condition;<\/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>The <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-inner-join\/\">inner join<\/a> clause joins two tables based on a condition which is known as a join predicate.<\/p>\n\n\n\n<p>The inner join clause compares each row from the first table with every row from the second table. <\/p>\n\n\n\n<p>If values from both rows satisfy the join condition, the inner join clause creates a new row whose column contains all columns of the two rows from both tables and includes this new row in the result set. In other words, the inner join clause includes only matching rows from both tables.<\/p>\n\n\n\n<p>If the join condition uses the equality operator (<code>=<\/code>) and the column names in both tables used for matching are the same, and you can use the <code>USING<\/code> clause instead:<\/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\"><span class=\"hljs-keyword\">SELECT<\/span> column_list\n<span class=\"hljs-keyword\">FROM<\/span> table_1\n<span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> table_2 <span class=\"hljs-keyword\">USING<\/span> (column_name);<\/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 following statement uses an inner join clause to find members who are also the committee members:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" 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    m.member_id, \n    m.name <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">member<\/span>, \n    c.committee_id, \n    c.name <span class=\"hljs-keyword\">AS<\/span> committee\n<span class=\"hljs-keyword\">FROM<\/span>\n    members m\n<span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> committees c <span class=\"hljs-keyword\">ON<\/span> c.name = m.name;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><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<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"plaintext\" data-shcb-language-slug=\"plaintext\"><span><code class=\"hljs language-plaintext\">+-----------+--------+--------------+-----------+\n| member_id | member | committee_id | committee |\n+-----------+--------+--------------+-----------+\n|         1 | John   |            1 | John      |\n|         3 | Mary   |            2 | Mary      |\n|         5 | Amelia |            3 | Amelia    |\n+-----------+--------+--------------+-----------+\n3 rows in set (0.00 sec)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">plaintext<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">plaintext<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this example, the inner join clause uses the values in the <code>name<\/code> columns in both tables <code>members<\/code> and <code>committees<\/code> to match.<\/p>\n\n\n\n<p>The following Venn diagram illustrates the inner join:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"393\" height=\"235\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/mysql-join-inner-join.png\" alt=\"mysql join - inner join\" class=\"wp-image-7836\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/mysql-join-inner-join.png 393w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/mysql-join-inner-join-200x120.png 200w\" sizes=\"auto, (max-width: 393px) 100vw, 393px\" \/><\/figure>\n\n\n\n<p>Because both tables use the same column to match, you can use the <code>USING<\/code> clause as shown in the following query:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" 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    m.member_id, \n    m.name <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">member<\/span>, \n    c.committee_id, \n    c.name <span class=\"hljs-keyword\">AS<\/span> committee\n<span class=\"hljs-keyword\">FROM<\/span>\n    members m\n<span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> committees c <span class=\"hljs-keyword\">USING<\/span>(<span class=\"hljs-keyword\">name<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><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\">MySQL LEFT JOIN clause<\/h2>\n\n\n\n<p>Similar to an inner join, a <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-left-join\/\">left join<\/a> also requires a join predicate. When joining two tables using a left join, the concepts of left and right tables are introduced.<\/p>\n\n\n\n<p>The left join selects data starting from the left table. For each row in the left table, the left join compares with every row in the right table. <\/p>\n\n\n\n<p>If the values in the two rows satisfy the join condition, the left join clause creates a new row whose columns contain all columns of the rows in both tables and includes this row in the result set.<\/p>\n\n\n\n<p>If the values in the two rows are not matched, the left join clause still creates a new row whose columns contain columns of the row in the left table and <code>NULL<\/code> for columns of the row in the right table.<\/p>\n\n\n\n<p>In other words, the left join selects all data from the left table whether there are matching rows exist in the right table or not. <\/p>\n\n\n\n<p>In case there are no matching rows from the right table found, the left join uses NULLs for columns of the row from the right table in the result set.<\/p>\n\n\n\n<p>Here is the basic syntax of a left join clause that joins two tables:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" 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> column_list \n<span class=\"hljs-keyword\">FROM<\/span> table_1 \n<span class=\"hljs-keyword\">LEFT<\/span> <span class=\"hljs-keyword\">JOIN<\/span> table_2 <span class=\"hljs-keyword\">ON<\/span> join_condition;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><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 left join also supports the <code>USING<\/code> clause if the column used for matching in both tables is the same:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" 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> column_list \n<span class=\"hljs-keyword\">FROM<\/span> table_1 \n<span class=\"hljs-keyword\">LEFT<\/span> <span class=\"hljs-keyword\">JOIN<\/span> table_2 <span class=\"hljs-keyword\">USING<\/span> (column_name);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><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 following example uses a left join clause to join the <code>members<\/code> with the <code>committees<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" 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    m.member_id, \n    m.name <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">member<\/span>, \n    c.committee_id, \n    c.name <span class=\"hljs-keyword\">AS<\/span> committee\n<span class=\"hljs-keyword\">FROM<\/span>\n    members m\n<span class=\"hljs-keyword\">LEFT<\/span> <span class=\"hljs-keyword\">JOIN<\/span> committees c <span class=\"hljs-keyword\">USING<\/span>(<span class=\"hljs-keyword\">name<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><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<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-15\" data-shcb-language-name=\"plaintext\" data-shcb-language-slug=\"plaintext\"><span><code class=\"hljs language-plaintext\">+-----------+--------+--------------+-----------+\n| member_id | member | committee_id | committee |\n+-----------+--------+--------------+-----------+\n|         1 | John   |            1 | John      |\n|         2 | Jane   |         NULL | NULL      |\n|         3 | Mary   |            2 | Mary      |\n|         4 | David  |         NULL | NULL      |\n|         5 | Amelia |            3 | Amelia    |\n+-----------+--------+--------------+-----------+\n5 rows in set (0.00 sec)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-15\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">plaintext<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">plaintext<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The following Venn diagram illustrates the left join:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"395\" height=\"226\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/mysql-join-left-join.png\" alt=\"mysql join - left join\" class=\"wp-image-7837\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/mysql-join-left-join.png 395w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/mysql-join-left-join-200x114.png 200w\" sizes=\"auto, (max-width: 395px) 100vw, 395px\" \/><\/figure>\n\n\n\n<p>This statement uses the left join clause with the <code>USING<\/code> syntax:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-16\" 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    m.member_id, \n    m.name <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">member<\/span>, \n    c.committee_id, \n    c.name <span class=\"hljs-keyword\">AS<\/span> committee\n<span class=\"hljs-keyword\">FROM<\/span>\n    members m\n<span class=\"hljs-keyword\">LEFT<\/span> <span class=\"hljs-keyword\">JOIN<\/span> committees c <span class=\"hljs-keyword\">USING<\/span>(<span class=\"hljs-keyword\">name<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-16\"><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>To find members who are not the committee members, you add a <code><a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-where\/\">WHERE<\/a><\/code> clause and <code><a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-is-null\/\">IS NULL<\/a><\/code> operator as follows:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-17\" 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    m.member_id, \n    m.name <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">member<\/span>, \n    c.committee_id, \n    c.name <span class=\"hljs-keyword\">AS<\/span> committee\n<span class=\"hljs-keyword\">FROM<\/span>\n    members m\n<span class=\"hljs-keyword\">LEFT<\/span> <span class=\"hljs-keyword\">JOIN<\/span> committees c <span class=\"hljs-keyword\">USING<\/span>(<span class=\"hljs-keyword\">name<\/span>)\n<span class=\"hljs-keyword\">WHERE<\/span> c.committee_id <span class=\"hljs-keyword\">IS<\/span> <span class=\"hljs-literal\">NULL<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-17\"><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<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-18\" data-shcb-language-name=\"plaintext\" data-shcb-language-slug=\"plaintext\"><span><code class=\"hljs language-plaintext\">+-----------+--------+--------------+-----------+\n| member_id | member | committee_id | committee |\n+-----------+--------+--------------+-----------+\n|         2 | Jane   |         NULL | NULL      |\n|         4 | David  |         NULL | NULL      |\n+-----------+--------+--------------+-----------+\n2 rows in set (0.00 sec)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-18\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">plaintext<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">plaintext<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Generally, this query pattern can find rows in the left table that do not have corresponding rows in the right table.<\/p>\n\n\n\n<p>This Venn diagram illustrates how to use the left join to select rows that only exist in the left table:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"350\" height=\"221\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/mysql-join-left-join-only-rows-in-the-left-table.png\" alt=\"mysql join - left join - only rows in the left table\" class=\"wp-image-7838\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/mysql-join-left-join-only-rows-in-the-left-table.png 350w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/mysql-join-left-join-only-rows-in-the-left-table-200x126.png 200w\" sizes=\"auto, (max-width: 350px) 100vw, 350px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">MySQL RIGHT JOIN clause<\/h2>\n\n\n\n<p>The <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-right-join\/\">right join<\/a> clause is similar to the left join clause except that the treatment of left and right tables is reversed. The right join starts selecting data from the right table instead of the left table.<\/p>\n\n\n\n<p>The right join clause selects all rows from the right table and matches rows in the left table. If a row from the right table does not have matching rows from the left table, the column of the left table will have <code>NULL<\/code> in the final result set.<\/p>\n\n\n\n<p>Here is the syntax of the right join:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-19\" 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> column_list \n<span class=\"hljs-keyword\">FROM<\/span> table_1 \n<span class=\"hljs-keyword\">RIGHT<\/span> <span class=\"hljs-keyword\">JOIN<\/span> table_2 <span class=\"hljs-keyword\">ON<\/span> join_condition;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-19\"><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>Similar to the left join clause, the right clause also supports the <code>USING<\/code> syntax:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-20\" 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> column_list \n<span class=\"hljs-keyword\">FROM<\/span> table_1 \n<span class=\"hljs-keyword\">RIGHT<\/span> <span class=\"hljs-keyword\">JOIN<\/span> table_2 <span class=\"hljs-keyword\">USING<\/span> (column_name);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-20\"><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>To find rows in the right table that do not have corresponding rows in the left table, you also use a <code><a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-where\/\">WHERE<\/a><\/code> clause with the <code><a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-is-null\/\">IS NULL<\/a><\/code> operator:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-21\" 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> column_list \n<span class=\"hljs-keyword\">FROM<\/span> table_1 \n<span class=\"hljs-keyword\">RIGHT<\/span> <span class=\"hljs-keyword\">JOIN<\/span> table_2 <span class=\"hljs-keyword\">USING<\/span> (column_name)\n<span class=\"hljs-keyword\">WHERE<\/span> column_table_1 <span class=\"hljs-keyword\">IS<\/span> <span class=\"hljs-literal\">NULL<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-21\"><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>This statement uses the right join to join the <code>members<\/code> and <code>committees<\/code> tables:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-22\" 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    m.member_id, \n    m.name <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">member<\/span>, \n    c.committee_id, \n    c.name <span class=\"hljs-keyword\">AS<\/span> committee\n<span class=\"hljs-keyword\">FROM<\/span>\n    members m\n<span class=\"hljs-keyword\">RIGHT<\/span> <span class=\"hljs-keyword\">JOIN<\/span> committees c <span class=\"hljs-keyword\">on<\/span> c.name = m.name;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-22\"><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<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-23\" data-shcb-language-name=\"plaintext\" data-shcb-language-slug=\"plaintext\"><span><code class=\"hljs language-plaintext\">+-----------+--------+--------------+-----------+\n| member_id | member | committee_id | committee |\n+-----------+--------+--------------+-----------+\n|         1 | John   |            1 | John      |\n|         3 | Mary   |            2 | Mary      |\n|         5 | Amelia |            3 | Amelia    |\n|      NULL | NULL   |            4 | Joe       |\n+-----------+--------+--------------+-----------+\n4 rows in set (0.00 sec)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-23\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">plaintext<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">plaintext<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This Venn diagram illustrates the right join:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"357\" height=\"220\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/mysql-join-right-join.png\" alt=\"mysql join - right join\" class=\"wp-image-7839\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/mysql-join-right-join.png 357w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/mysql-join-right-join-200x123.png 200w\" sizes=\"auto, (max-width: 357px) 100vw, 357px\" \/><\/figure>\n\n\n\n<p>The following statement uses the right join clause with the <code>USING<\/code> syntax:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-24\" 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    m.member_id, \n    m.name <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">member<\/span>, \n    c.committee_id, \n    c.name <span class=\"hljs-keyword\">AS<\/span> committee\n<span class=\"hljs-keyword\">FROM<\/span>\n    members m\n<span class=\"hljs-keyword\">RIGHT<\/span> <span class=\"hljs-keyword\">JOIN<\/span> committees c <span class=\"hljs-keyword\">USING<\/span>(<span class=\"hljs-keyword\">name<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-24\"><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>To find the committee members who are not in the <code>members<\/code> table, you use this query:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-25\" 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    m.member_id, \n    m.name <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">member<\/span>, \n    c.committee_id, \n    c.name <span class=\"hljs-keyword\">AS<\/span> committee\n<span class=\"hljs-keyword\">FROM<\/span>\n    members m\n<span class=\"hljs-keyword\">RIGHT<\/span> <span class=\"hljs-keyword\">JOIN<\/span> committees c <span class=\"hljs-keyword\">USING<\/span>(<span class=\"hljs-keyword\">name<\/span>)\n<span class=\"hljs-keyword\">WHERE<\/span> m.member_id <span class=\"hljs-keyword\">IS<\/span> <span class=\"hljs-literal\">NULL<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-25\"><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<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-26\" data-shcb-language-name=\"plaintext\" data-shcb-language-slug=\"plaintext\"><span><code class=\"hljs language-plaintext\">+-----------+--------+--------------+-----------+\n| member_id | member | committee_id | committee |\n+-----------+--------+--------------+-----------+\n|      NULL | NULL   |            4 | Joe       |\n+-----------+--------+--------------+-----------+\n1 row in set (0.00 sec)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-26\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">plaintext<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">plaintext<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This Venn diagram illustrates how to use the right join to select data that exists only in the right table:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"363\" height=\"208\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/mysql-join-right-join-only-rows-in-the-right-table.png\" alt=\"\" class=\"wp-image-7879\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/mysql-join-right-join-only-rows-in-the-right-table.png 363w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/mysql-join-right-join-only-rows-in-the-right-table-200x115.png 200w\" sizes=\"auto, (max-width: 363px) 100vw, 363px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">MySQL CROSS JOIN clause<\/h2>\n\n\n\n<p>Unlike the <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-inner-join\/\">inner join<\/a>, <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-left-join\/\">left join<\/a>, and <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-right-join\/\">right join<\/a>, the <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-cross-join\/\">cross join<\/a> clause does not have a join condition. <\/p>\n\n\n\n<p>The cross join makes a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Cartesian_product\" target=\"_blank\" rel=\"noreferrer noopener\">Cartesian product<\/a> of rows from the joined tables. The cross join combines each row from the first table with every row from the right table to make the result set.<\/p>\n\n\n\n<p>Suppose the first table has <code>n<\/code> rows and the second table has <code>m<\/code> rows. The cross-join that joins the tables will return <code>nxm<\/code> rows.<\/p>\n\n\n\n<p>The following shows the syntax of the cross-join clause:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-27\" 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> select_list\n<span class=\"hljs-keyword\">FROM<\/span> table_1\n<span class=\"hljs-keyword\">CROSS<\/span> <span class=\"hljs-keyword\">JOIN<\/span> table_2;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-27\"><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>This example uses the cross join clause to join the <code>members<\/code> with the <code>committees<\/code> tables:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-28\" 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    m.member_id, \n    m.name <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">member<\/span>, \n    c.committee_id, \n    c.name <span class=\"hljs-keyword\">AS<\/span> committee\n<span class=\"hljs-keyword\">FROM<\/span>\n    members m\n<span class=\"hljs-keyword\">CROSS<\/span> <span class=\"hljs-keyword\">JOIN<\/span> committees c;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-28\"><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<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-29\" data-shcb-language-name=\"plaintext\" data-shcb-language-slug=\"plaintext\"><span><code class=\"hljs language-plaintext\">+-----------+--------+--------------+-----------+\n| member_id | member | committee_id | committee |\n+-----------+--------+--------------+-----------+\n|         1 | John   |            4 | Joe       |\n|         1 | John   |            3 | Amelia    |\n|         1 | John   |            2 | Mary      |\n|         1 | John   |            1 | John      |\n|         2 | Jane   |            4 | Joe       |\n|         2 | Jane   |            3 | Amelia    |\n|         2 | Jane   |            2 | Mary      |\n|         2 | Jane   |            1 | John      |\n|         3 | Mary   |            4 | Joe       |\n|         3 | Mary   |            3 | Amelia    |\n|         3 | Mary   |            2 | Mary      |\n|         3 | Mary   |            1 | John      |\n|         4 | David  |            4 | Joe       |\n|         4 | David  |            3 | Amelia    |\n|         4 | David  |            2 | Mary      |\n|         4 | David  |            1 | John      |\n|         5 | Amelia |            4 | Joe       |\n|         5 | Amelia |            3 | Amelia    |\n|         5 | Amelia |            2 | Mary      |\n|         5 | Amelia |            1 | John      |\n+-----------+--------+--------------+-----------+\n20 rows in set (0.00 sec)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-29\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">plaintext<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">plaintext<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The cross join is useful for generating planning data. For example, you can carry the sales planning by using the cross join of customers, products, and years.<\/p>\n\n\n\n<p>In this tutorial, you have learned various MySQL join statements, including cross join, inner join, left join, and right join, to query data from two tables.<\/p>\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=\"6351\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-join\/\"\n\t\t\t\tdata-post-title=\"MySQL 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=\"6351\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-join\/\"\n\t\t\t\tdata-post-title=\"MySQL 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>This tutorial explains the MySQL join concept and introduces to you various kinds of joins including left join, right join and inner join.<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":174,"menu_order":14,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-6351","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>MySQL Join Made Easy For Beginners<\/title>\n<meta name=\"description\" content=\"This tutorial explains the MySQL join concept and introduces to you various kinds of joins including left join, right join, and inner join.\" \/>\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.mysqltutorial.org\/mysql-basics\/mysql-join\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MySQL Join Made Easy For Beginners\" \/>\n<meta property=\"og:description\" content=\"This tutorial explains the MySQL join concept and introduces to you various kinds of joins including left join, right join, and inner join.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-join\/\" \/>\n<meta property=\"og:site_name\" content=\"MySQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-05T08:33:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2009\/12\/orders_order_details_tables.png\" \/>\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.mysqltutorial.org\\\/mysql-basics\\\/mysql-join\\\/\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-join\\\/\",\"name\":\"MySQL Join Made Easy For Beginners\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-join\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-join\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2009\\\/12\\\/orders_order_details_tables.png\",\"datePublished\":\"2017-07-15T15:20:59+00:00\",\"dateModified\":\"2024-01-05T08:33:21+00:00\",\"description\":\"This tutorial explains the MySQL join concept and introduces to you various kinds of joins including left join, right join, and inner join.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-join\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-join\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-join\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2009\\\/12\\\/orders_order_details_tables.png\",\"contentUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2009\\\/12\\\/orders_order_details_tables.png\",\"width\":444,\"height\":194,\"caption\":\"MySQL Transaction: orders & orderDetails Tables\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-join\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MySQL Basics\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"MySQL Join\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\",\"name\":\"MySQL Tutorial\",\"description\":\"A comprehensive MySQL Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mysqltutorial.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":"MySQL Join Made Easy For Beginners","description":"This tutorial explains the MySQL join concept and introduces to you various kinds of joins including left join, right join, and inner join.","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.mysqltutorial.org\/mysql-basics\/mysql-join\/","og_locale":"en_US","og_type":"article","og_title":"MySQL Join Made Easy For Beginners","og_description":"This tutorial explains the MySQL join concept and introduces to you various kinds of joins including left join, right join, and inner join.","og_url":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-join\/","og_site_name":"MySQL Tutorial","article_modified_time":"2024-01-05T08:33:21+00:00","og_image":[{"url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2009\/12\/orders_order_details_tables.png","type":"","width":"","height":""}],"twitter_misc":{"Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-join\/","url":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-join\/","name":"MySQL Join Made Easy For Beginners","isPartOf":{"@id":"https:\/\/www.mysqltutorial.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-join\/#primaryimage"},"image":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-join\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2009\/12\/orders_order_details_tables.png","datePublished":"2017-07-15T15:20:59+00:00","dateModified":"2024-01-05T08:33:21+00:00","description":"This tutorial explains the MySQL join concept and introduces to you various kinds of joins including left join, right join, and inner join.","breadcrumb":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-join\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-join\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-join\/#primaryimage","url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2009\/12\/orders_order_details_tables.png","contentUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2009\/12\/orders_order_details_tables.png","width":444,"height":194,"caption":"MySQL Transaction: orders & orderDetails Tables"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-join\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.mysqltutorial.org\/"},{"@type":"ListItem","position":2,"name":"MySQL Basics","item":"https:\/\/www.mysqltutorial.org\/mysql-basics\/"},{"@type":"ListItem","position":3,"name":"MySQL Join"}]},{"@type":"WebSite","@id":"https:\/\/www.mysqltutorial.org\/#website","url":"https:\/\/www.mysqltutorial.org\/","name":"MySQL Tutorial","description":"A comprehensive MySQL Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mysqltutorial.org\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/6351","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/comments?post=6351"}],"version-history":[{"count":5,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/6351\/revisions"}],"predecessor-version":[{"id":14257,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/6351\/revisions\/14257"}],"up":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/174"}],"wp:attachment":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media?parent=6351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}