title: SQL multiple selects on same table and column for data filtering
body: <p>I know I've done this before, but haven't done much SQL in a while.</p>
  
  <p>I have a table called lead_detail, it has the following columns: <code>id</code>, <code>lead_id</code>, <code>form_id</code>, <code>field_number</code>, <code>value</code>.</p>
  
  <p>I'm trying to get results and then filter them.</p>
  
  <p>So, originally, I got all the lead ids that had a particular answer for a particular question.</p>
  
  <p>Let's say the first filter was that I wanted all results for an answer of "yes" to a question of "do you like chicken" (field_number of 4).</p>
  
  <pre><code>$leadIds = query(SELECT lead_id FROM lead_detail WHERE field_number = '4' AND value = 'yes' AND form_id = '1')
  $leadIds = implode(', ', $leadIds);
  </code></pre>
  
  <p>Then, I could get the appropriate filtered data by</p>
  
  <p><code>SELECT * FROM lead_detail WHERE form_id = '1' and lead_id IN ($leadIds)</code></p>
  
  <p>This works perfectly.</p>
  
  <p>If I want to add a SECOND filter though, I need to do two queries to the same columns in the same query.  I'm thinking I need to do some kind of join with table aliases, or some sub selects, but can't remember how to do it.</p>
  
  <p>So if I needed to know who answered "yes" to a question of "do you like chicken" AND who answered "18-24" on "what is your age", how would I get the appropriate $leadIds?</p>
  
  <p>It'd be something like the combination of </p>
  
  <pre><code>SELECT lead_id FROM lead_detail WHERE field_number = '4' AND value = 'yes' AND form_id = '1'
  AND
  SELECT lead_id FROM lead_detail WHERE field_number = '5' AND value = '18-24' AND form_id = '1'
  </code></pre>