title: How to SELECT the newest four items per category?
body: <p>I have a database of items.  Each item is categorized with a category ID from a category table.  I am trying to create a page that lists every category, and underneath each category I want to show the 4 newest items in that category.</p>
  
  <p><em>For Example:</em></p>
  
  <p><strong>Pet Supplies</strong><br/></p>
  
  <pre><code>img1
  img2
  img3
  img4
  </code></pre>
  
  <p><strong>Pet Food</strong><br/></p>
  
  <pre><code>img1
  img2
  img3
  img4
  </code></pre>
  
  <p>I know that I could easily solve this problem by querying the database for each category like so:</p>
  
  <pre>SELECT id FROM category</pre>
  
  <p>Then iterating over that data and querying the database for each category to grab the newest items:</p>
  
  <pre>SELECT image FROM item where category_id = :category_id 
  ORDER BY date_listed DESC LIMIT 4</pre>
  
  <p>What I'm trying to figure out is if I can just use 1 query and grab all of that data.  I have 33 categories so I thought perhaps it would help reduce the number of calls to the database.</p>
  
  <p>Anyone know if this is possible?  Or if 33 calls isn't that big a deal and I should just do it the easy way.</p>