{"id":13742,"date":"2023-12-29T00:39:29","date_gmt":"2023-12-29T07:39:29","guid":{"rendered":"https:\/\/www.mysqltutorial.org\/?page_id=13742"},"modified":"2023-12-31T02:32:33","modified_gmt":"2023-12-31T09:32:33","slug":"mysql-inner-join","status":"publish","type":"page","link":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-inner-join\/","title":{"rendered":"MySQL INNER JOIN"},"content":{"rendered":"\n<p><strong>Summary<\/strong><em>:<\/em> in this tutorial, you will learn how to use the MySQL <code>INNER JOIN<\/code> clause to select data from multiple tables based on join conditions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction to MySQL INNER JOIN clause<\/h2>\n\n\n\n<p>The <code>INNER JOIN<\/code> matches each row in one table with every row in other tables and allows you to query rows that contain columns from both tables.<\/p>\n\n\n\n<p>The <code>INNER JOIN<\/code> is an optional clause of the <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-select-from\/\"><code>SELECT<\/code><\/a> statement. It appears immediately after the <code>FROM<\/code> clause. <\/p>\n\n\n\n<p>Here is 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=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span>\n    select_list\n<span class=\"hljs-keyword\">FROM<\/span> t1\n<span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> t2 <span class=\"hljs-keyword\">ON<\/span> join_condition1\n<span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> t3 <span class=\"hljs-keyword\">ON<\/span> join_condition2\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>In this syntax:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, specify the main table that appears in the <code>FROM<\/code> clause (<code>t1<\/code>).<\/li>\n\n\n\n<li>Second, specify the table that will be joined with the main table, which appears in the <code>INNER JOIN<\/code> clause (<code>t2<\/code>, <code>t3<\/code>,&#8230;).<\/li>\n\n\n\n<li>Third, specify a join condition after the <code>ON<\/code> keyword of the <code>INNER JOIN<\/code> clause. The join condition specifies the rule for matching rows between the main table and the table that appeared in the <code>INNER JOIN<\/code> clause.<\/li>\n<\/ul>\n\n\n\n<p>Assuming that you want to join two tables <code>t1<\/code> and <code>t2<\/code>.<\/p>\n\n\n\n<p>The following statement illustrates how to join two tables <code>t1<\/code> and <code>t2<\/code> using the <code>INNER JOIN<\/code> clause:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> \n     select_list\n<span class=\"hljs-keyword\">FROM<\/span> \n     t1\n<span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> t2 <span class=\"hljs-keyword\">ON<\/span> join_condition;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The <code>INNER JOIN<\/code> clause compares each row in the <code>t1<\/code> table with every row in the <code>t2<\/code> table based on the join condition.<\/p>\n\n\n\n<p>If rows from both tables cause the join condition to evaluate to <code>TRUE<\/code>, the <code>INNER JOIN<\/code> creates a new row whose columns contain all columns of rows from the tables and includes this new row in the result set. Otherwise, the <code>INNER JOIN<\/code> just ignores the rows.<\/p>\n\n\n\n<p>If no row between tables causes the join condition to be evaluated to <code>TRUE<\/code>, the <code>INNER JOIN<\/code> returns an empty result set. <\/p>\n\n\n\n<p>This logic is also applied when you join more than 2 tables.<\/p>\n\n\n\n<p>The following Venn diagram illustrates how the <code>INNER JOIN<\/code> clause works:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"166\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2011\/05\/MySQL-INNER-JOIN-Venn-Diagram-300x166.png\" alt=\"MySQL INNER JOIN Venn Diagram\" class=\"wp-image-1877\" title=\"MySQL INNER JOIN Venn Diagram\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2011\/05\/MySQL-INNER-JOIN-Venn-Diagram-300x166.png 300w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2011\/05\/MySQL-INNER-JOIN-Venn-Diagram.png 534w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">MySQL INNER JOIN examples<\/h2>\n\n\n\n<p>Let&#8217;s look at the <code>products<\/code> and <code>productlines<\/code> tables in the <a title=\"MySQL Sample Database\" href=\"https:\/\/www.mysqltutorial.org\/getting-started-with-mysql\/mysql-sample-database\/\">sample database<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"371\" height=\"231\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/products-productlines-tables.png\" alt=\"products productlines tables\" class=\"wp-image-7870\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/products-productlines-tables.png 371w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/products-productlines-tables-200x125.png 200w\" sizes=\"auto, (max-width: 371px) 100vw, 371px\" \/><\/figure>\n\n\n\n<p>In this diagram, the table <code>products<\/code> has the column <code>productLine<\/code> that references the column&nbsp; <code>productline<\/code> of the table <code>productlines<\/code> . The column <code>productLine<\/code> in the table <code>products<\/code> is called the <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-foreign-key\/\">foreign key<\/a> column.<\/p>\n\n\n\n<p>Typically, you join tables that have foreign key relationships like the&nbsp;&nbsp;<code>productlines<\/code> and <code>products<\/code> tables.<\/p>\n\n\n\n<p>Suppose you want to get:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The <code>productCode<\/code><em>&nbsp;<\/em>and <code>productName<\/code> from the <code>products<\/code> table.<\/li>\n\n\n\n<li>The <code>textDescription<\/code> of product lines from the <code>productlines<\/code> table<em>.<\/em><\/li>\n<\/ul>\n\n\n\n<p>To do this, you need to select data from both tables by matching rows based on values in the <code>productline<\/code> column using the <code>INNER JOIN<\/code> clause as follows:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> \n    productCode, \n    productName, \n    textDescription\n<span class=\"hljs-keyword\">FROM<\/span>\n    products t1\n<span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> productlines t2 \n    <span class=\"hljs-keyword\">ON<\/span> t1.productline = t2.productline;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a class=\"sql\" href=\"https:\/\/www.mysqltutorial.org\/tryit\/query\/mysql-inner-join\/#1\" target=\"_blank\" rel=\"noopener noreferrer\">Try It Out<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-4995 size-full\" title=\"MySQL INNER JOIN - Products Data Example\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2011\/05\/MySQL-INNER-JOIN-Products-Data-Example.jpg\" alt=\"MySQL INNER JOIN - Products Data Example\" width=\"627\" height=\"132\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2011\/05\/MySQL-INNER-JOIN-Products-Data-Example.jpg 627w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2011\/05\/MySQL-INNER-JOIN-Products-Data-Example-300x63.jpg 300w\" sizes=\"auto, (max-width: 627px) 100vw, 627px\" \/><\/h3>\n\n\n\n<p>Because the joined columns of both tables have the same name &nbsp;<code>productline<\/code>, you can use the <code>USING<\/code> syntax:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" 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    productCode, \n    productName, \n    textDescription\n<span class=\"hljs-keyword\">FROM<\/span>\n    products\n<span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> productlines <span class=\"hljs-keyword\">USING<\/span> (productline);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><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 query returns the same result set. However, the <code>USING<\/code> syntax is much shorter and cleaner.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">MySQL INNER JOIN with GROUP BY clause example<\/h3>\n\n\n\n<p>See the following <code>orders<\/code> and <code>orderdetails<\/code> tables:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"424\" height=\"184\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/orders-orderdetails-table.png\" alt=\"orders orderdetails table\" class=\"wp-image-7867\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/orders-orderdetails-table.png 424w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/orders-orderdetails-table-200x87.png 200w\" sizes=\"auto, (max-width: 424px) 100vw, 424px\" \/><\/figure>\n\n\n\n<p>This query returns the order number, order status, and total sales from the <code>orders<\/code> and <code>orderdetails<\/code> tables using the <code>INNER JOIN<\/code> clause with the <code><a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-group-by\/\">GROUP BY<\/a><\/code>clause:<\/p>\n\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> \n    t1.orderNumber,\n    t1.status,\n    <span class=\"hljs-keyword\">SUM<\/span>(quantityOrdered * priceEach) total\n<span class=\"hljs-keyword\">FROM<\/span>\n    orders t1\n<span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> orderdetails t2 \n    <span class=\"hljs-keyword\">ON<\/span> t1.orderNumber = t2.orderNumber\n<span class=\"hljs-keyword\">GROUP<\/span> <span class=\"hljs-keyword\">BY<\/span> t1.orderNumber;<\/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\n<p><a class=\"sql\" href=\"https:\/\/www.mysqltutorial.org\/tryit\/query\/mysql-inner-join\/#2\" target=\"_blank\" rel=\"noopener noreferrer\">Try It Out<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"265\" height=\"132\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2011\/05\/MysQL-INNER-JOIN-with-GROUP-BY-clause.jpg\" alt=\"MysQL INNER JOIN with GROUP BY clause\" class=\"wp-image-4994\" title=\"MysQL INNER JOIN with GROUP BY clause\"\/><\/figure>\n\n\n\n<p>Similarly, the following query uses the <code>INNER JOIN<\/code> with the <code>USING<\/code> syntax:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> \n    orderNumber,\n    <span class=\"hljs-keyword\">status<\/span>,\n    <span class=\"hljs-keyword\">SUM<\/span>(quantityOrdered * priceEach) total\n<span class=\"hljs-keyword\">FROM<\/span>\n    orders\n<span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> orderdetails <span class=\"hljs-keyword\">USING<\/span> (orderNumber)\n<span class=\"hljs-keyword\">GROUP<\/span> <span class=\"hljs-keyword\">BY<\/span> orderNumber;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">MySQL INNER JOIN &#8211; join three tables example<\/h3>\n\n\n\n<p>See the following <code>products<\/code>, <code>orders<\/code> and <code>orderdetails<\/code> tables:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"719\" height=\"224\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/products-orders-orderdetails-tables.png\" alt=\"\" class=\"wp-image-7863\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/products-orders-orderdetails-tables.png 719w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/products-orders-orderdetails-tables-200x62.png 200w\" sizes=\"auto, (max-width: 719px) 100vw, 719px\" \/><\/figure>\n\n\n\n<p>This query uses two <code>INNER JOIN<\/code> clauses to join three tables: <code>orders<\/code>, <code>orderdetails<\/code>, and <code>products<\/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> \n    orderNumber,\n    orderDate,\n    orderLineNumber,\n    productName,\n    quantityOrdered,\n    priceEach\n<span class=\"hljs-keyword\">FROM<\/span>\n    orders\n<span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span>\n    orderdetails <span class=\"hljs-keyword\">USING<\/span> (orderNumber)\n<span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span>\n    products <span class=\"hljs-keyword\">USING<\/span> (productCode)\n<span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span> \n    orderNumber, \n    orderLineNumber;<\/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>This picture shows the partial output:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"656\" height=\"280\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/MySQL-Inner-Join-join-three-tables-example.png\" alt=\"MySQL Inner Join - join three tables example\" class=\"wp-image-7864\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/MySQL-Inner-Join-join-three-tables-example.png 656w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/MySQL-Inner-Join-join-three-tables-example-200x85.png 200w\" sizes=\"auto, (max-width: 656px) 100vw, 656px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">MySQL INNER JOIN &#8211; join four tables example<\/h3>\n\n\n\n<p>See the following <code>orders<\/code>, <code>orderdetails<\/code>, <code>customers<\/code> and <code>products<\/code> tables:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"503\" height=\"563\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/orders-orderdetails-products-customers-tables.png\" alt=\"orders orderdetails products customers tables\" class=\"wp-image-7865\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/orders-orderdetails-products-customers-tables.png 503w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/orders-orderdetails-products-customers-tables-179x200.png 179w\" sizes=\"auto, (max-width: 503px) 100vw, 503px\" \/><\/figure>\n\n\n\n<p>This example uses three <code>INNER JOIN<\/code> clauses to query data from the four tables above:<\/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> \n    orderNumber,\n    orderDate,\n    customerName,\n    orderLineNumber,\n    productName,\n    quantityOrdered,\n    priceEach\n<span class=\"hljs-keyword\">FROM<\/span>\n    orders\n<span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> orderdetails \n    <span class=\"hljs-keyword\">USING<\/span> (orderNumber)\n<span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> products \n    <span class=\"hljs-keyword\">USING<\/span> (productCode)\n<span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> customers \n    <span class=\"hljs-keyword\">USING<\/span> (customerNumber)\n<span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span> \n    orderNumber, \n    orderLineNumber;<\/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<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"916\" height=\"397\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/MySQL-Inner-Join-join-four-tables-example.png\" alt=\"MySQL Inner Join - join four tables example\" class=\"wp-image-7866\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/MySQL-Inner-Join-join-four-tables-example.png 916w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/MySQL-Inner-Join-join-four-tables-example-200x87.png 200w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/MySQL-Inner-Join-join-four-tables-example-768x333.png 768w\" sizes=\"auto, (max-width: 916px) 100vw, 916px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">MySQL INNER JOIN using other operators<\/h2>\n\n\n\n<p>So far, you have seen that the join condition used the equal operator (=) for matching rows.<\/p>\n\n\n\n<p>In addition to the equal operator (=), you can use other operators such as greater than ( <code>&gt;<\/code>), less than ( <code>&lt;<\/code>), and not-equal ( <code>&lt;&gt;<\/code>) operator to form the join condition.<\/p>\n\n\n\n<p>The following query uses a less-than (&nbsp;<code>&lt;<\/code>) join to find the sales price of the product whose code is <code>S10_1678<\/code> that is less than the manufacturer&#8217;s suggested retail price (MSRP) for that product.<\/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    orderNumber, \n    productName, \n    msrp, \n    priceEach\n<span class=\"hljs-keyword\">FROM<\/span>\n    products p\n<span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> orderdetails o \n   <span class=\"hljs-keyword\">ON<\/span> p.productcode = o.productcode\n      <span class=\"hljs-keyword\">AND<\/span> p.msrp &gt; o.priceEach\n<span class=\"hljs-keyword\">WHERE<\/span>\n    p.productcode = <span class=\"hljs-string\">'S10_1678'<\/span>;<\/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\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"438\" height=\"175\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2011\/05\/MySQL-INNER-JOIN-not-equal-join-example.png\" alt=\"MySQL INNER JOIN - not-equal join example\" class=\"wp-image-6253\" title=\"MySQL INNER JOIN - not-equal join example\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2011\/05\/MySQL-INNER-JOIN-not-equal-join-example.png 438w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2011\/05\/MySQL-INNER-JOIN-not-equal-join-example-300x120.png 300w\" sizes=\"auto, (max-width: 438px) 100vw, 438px\" \/><\/figure>\n\n\n\n<p>In this tutorial, you have learned how to use the MySQL <code>INNER JOIN<\/code> to query data from multiple 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=\"13742\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-inner-join\/\"\n\t\t\t\tdata-post-title=\"MySQL 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=\"13742\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-inner-join\/\"\n\t\t\t\tdata-post-title=\"MySQL 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>Summary: in this tutorial, you will learn how to use the MySQL INNER JOIN clause to select data from multiple tables based on join conditions. Introduction to MySQL INNER JOIN clause The INNER JOIN matches each row in one table with every row in other tables and allows you to query rows that contain columns [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":174,"menu_order":15,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-13742","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 INNER JOIN<\/title>\n<meta name=\"description\" content=\"In this tutorial, you will learn how to use MySQL INNER JOIN clause to select data from multiple tables based on join conditions.\" \/>\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-inner-join\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MySQL INNER JOIN\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, you will learn how to use MySQL INNER JOIN clause to select data from multiple tables based on join conditions.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-inner-join\/\" \/>\n<meta property=\"og:site_name\" content=\"MySQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-31T09:32:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2011\/05\/MySQL-INNER-JOIN-Venn-Diagram-300x166.png\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-inner-join\\\/\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-inner-join\\\/\",\"name\":\"MySQL INNER JOIN\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-inner-join\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-inner-join\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2011\\\/05\\\/MySQL-INNER-JOIN-Venn-Diagram-300x166.png\",\"datePublished\":\"2023-12-29T07:39:29+00:00\",\"dateModified\":\"2023-12-31T09:32:33+00:00\",\"description\":\"In this tutorial, you will learn how to use MySQL INNER JOIN clause to select data from multiple tables based on join conditions.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-inner-join\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-inner-join\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-inner-join\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2011\\\/05\\\/MySQL-INNER-JOIN-Venn-Diagram.png\",\"contentUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2011\\\/05\\\/MySQL-INNER-JOIN-Venn-Diagram.png\",\"width\":534,\"height\":295,\"caption\":\"MySQL INNER JOIN Venn Diagram\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-inner-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 INNER 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 INNER JOIN","description":"In this tutorial, you will learn how to use MySQL INNER JOIN clause to select data from multiple tables based on join conditions.","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-inner-join\/","og_locale":"en_US","og_type":"article","og_title":"MySQL INNER JOIN","og_description":"In this tutorial, you will learn how to use MySQL INNER JOIN clause to select data from multiple tables based on join conditions.","og_url":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-inner-join\/","og_site_name":"MySQL Tutorial","article_modified_time":"2023-12-31T09:32:33+00:00","og_image":[{"url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2011\/05\/MySQL-INNER-JOIN-Venn-Diagram-300x166.png","type":"","width":"","height":""}],"twitter_misc":{"Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-inner-join\/","url":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-inner-join\/","name":"MySQL INNER JOIN","isPartOf":{"@id":"https:\/\/www.mysqltutorial.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-inner-join\/#primaryimage"},"image":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-inner-join\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2011\/05\/MySQL-INNER-JOIN-Venn-Diagram-300x166.png","datePublished":"2023-12-29T07:39:29+00:00","dateModified":"2023-12-31T09:32:33+00:00","description":"In this tutorial, you will learn how to use MySQL INNER JOIN clause to select data from multiple tables based on join conditions.","breadcrumb":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-inner-join\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-inner-join\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-inner-join\/#primaryimage","url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2011\/05\/MySQL-INNER-JOIN-Venn-Diagram.png","contentUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2011\/05\/MySQL-INNER-JOIN-Venn-Diagram.png","width":534,"height":295,"caption":"MySQL INNER JOIN Venn Diagram"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-inner-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 INNER 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\/13742","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=13742"}],"version-history":[{"count":3,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/13742\/revisions"}],"predecessor-version":[{"id":13936,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/13742\/revisions\/13936"}],"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=13742"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}