title: SQL - Should I use a join?
body: <p>I have the following sample query (MySQL):</p>
  
  <pre><code>SELECT * FROM `action` 
  WHERE `customer_id` IN 
      (SELECT `id` FROM `customer` WHERE `status`=1)
  ORDER BY
      action.date ASC
  LIMIT 0, 10
  </code></pre>
  
  <p>I need to be able to ORDER BY the customer.status field. Do I accomplish this with a join?</p>
  
  <p><code>status</code> is a field on the <code>customer</code> table.</p>
  
  <hr>
  
  <p>Edited Query:</p>
  
  <pre><code>SELECT * FROM `action` 
  ORDER BY
      action.date ASC
  LIMIT 0, 10
  </code></pre>
  
  <hr>
  
  <p>IMPORTANT!</p>
  
  <p>I am parsing the return data via PHP. After running the revised query:</p>
  
  <pre><code>SELECT * FROM `action` a INNER JOIN `customer` c ON a.customer_id = c.id ORDER BY a.form_id ASC LIMIT 0, 10
  </code></pre>
  
  <p>My PHP code breaks...</p>
  
  <hr>
  
  <p><a href="https://stackoverflow.com/a/431397/674033">This post</a> helped me out.</p>
  
  <p>My revised query looks like this:</p>
  
  <pre><code>SELECT 
      *, a.id AS lead_id, c.id AS customer_id 
  FROM 
      `action` a 
  INNER JOIN 
      `customer` c ON a.customer_id = c.id 
  ORDER BY c.status DESC
  </code></pre>
  
  <p>Thanks everyone!</p>
  
  <hr>
  
  <p>UPDATE</p>
  
  <p>Because I have some customer records without an action record, an INNER JOIN was not returning all relevant records. I use a JOIN now, and all results come back as expected.</p>