title: MySQL - Using results from one query to use in another query
body: <p>Let's say I have this, that produces 50,000 rows:</p>
  
  <pre><code>SELECT photoID FROM photoSearch WHERE photoID BETWEEN 1 AND 50000;
  </code></pre>
  
  <p>I was going to run this query against those photoID's just returned.</p>
  
  <pre><code>SELECT COUNT(people) AS totalPeople, people
  FROM people
  INNER JOIN photopeople ON photoPeople.peopleID = people.PeopleID
  WHERE photoid IN ('ID's from results')
  GROUP BY people
  ORDER BY totalPeople DESC
  </code></pre>
  
  <p>But I understand from others and resources, that the IN clause will not perform well, especially as I could have 100,000 plus photoID's.</p>
  
  <p>Is it a good idea to store the photoID's from the top query in another table (resultsTbl) or in a very long string? If yes to either, do I use a join or a sub-select to query those ID's (in the bottom query), instead of using IN? Or... is there another way that will do the job keeping performance in mind?</p>
  
  <p>Any help on this would be gratefully received.</p>