title: using "order by" on inner join MySql?
body: <p>hello master around the world, im here again with a problem :D</p>
  
  <p>now i wanna ask something simple for you but really I'm new on programming and sql, so need more learn.</p>
  
  <p>ok, lets to the problem. I have some sql query like this</p>
  
  <pre><code>SELECT
  eu_product.*,
  eu_shop_display.display_name as dname,
  eu_product_img.image_url as img
  FROM eu_product
  INNER JOIN eu_product_img on eu_product_img.product_id = eu_product.product_id
  INNER JOIN eu_shop_display on eu_shop_display.display_id = eu_product.product_display
  where eu_product.publish=1
  and eu_product.shop_id=1
  and eu_product.product_display IN (select display_id from eu_shop_display where parent_id=1) 
  or eu_product.product_display = 1
  GROUP BY eu_product.product_id 
  ORDER BY eu_product.product_id DESC  LIMIT 0, 10
  </code></pre>
  
  <p>The problem is in </p>
  
  <blockquote>
    <p>INNER JOIN eu_product_img on
    eu_product_img.product_id =
    eu_product.product_id</p>
  </blockquote>
  
  <p>the table seen like this</p>
  
  <p><img src="https://i.stack.imgur.com/oARIa.png" alt="enter image description here"></p>
  
  <p>I need to using Order ASC on field "listing".</p>
  
  <p>is SQL query can use two order by, or can adding order by in inner join ? i try adding</p>
  
  <pre><code>ORDER BY eu_product.product_id DESC, eu_product_img.listing ASC
  </code></pre>
  
  <p>but its not working :(</p>
  
  <p>maybe someone can explain how its work.</p>
  
  <hr>
  
  <p><strong>UPDATE</strong></p>
  
  <blockquote>
    <p>.&lt; maybe i'll make simple query</p>
  </blockquote>
  
  <p>this product table</p>
  
  <p><img src="https://i.stack.imgur.com/zRESg.png" alt="enter image description here"></p>
  
  <p>this product_img table</p>
  
  <p><img src="https://i.stack.imgur.com/oARIa.png" alt="enter image description here"></p>
  
  <p>and this a result</p>
  
  <p><img src="https://i.stack.imgur.com/6F9Sa.png" alt="enter image description here"></p>
  
  <p>but the " eu_product_img.listing ASC " not run correctly :(</p>
  
  <p><strong>i need the listing on product_id 1 is 1 not 4</strong></p>
  
  <p>see the table product_img</p>
  
  <p>i need run the product_img.listing order ASC first before joined it.</p>
  
  <p>the correct query is like this</p>
  
  <pre><code>SELECT eu_product.product_id, 
  (select img.listing from eu_product_img as img where img.product_id = eu_product.product_id order by img.listing ASC limit 1 ) as listing 
      FROM eu_product 
      where eu_product.shop_id=1 
      or eu_product.product_display = 2 
      GROUP BY eu_product.product_id 
      ORDER BY eu_product.product_id DESC  LIMIT 0, 20
  </code></pre>
  
  <p>so it cannot using inner join ?</p>
  
  <p>thanks before.</p>
  
  <p>Regard,
  Stecy</p>