title: MYSQL: SELECT sum of field values while also SELECTing unique values?
body: <p>I'd like to count the number of purchases of each item while also, depending on who's viewing the content, show whether the user has purchased the content. Because the number of items and purchases could become large I'm reluctant to throw in more <code>JOINs</code> to accomplish this because that would seem not performant.</p>
  
  <p>Basically, I'd like to have a <code>did_i_buy</code> field somewhere in the following query without adding another <code>JOIN</code>. Is this possible? Let's say for <code>user_name=tom</code>:  </p>
  
  <pre><code>SELECT Items.item_id, item_name, COUNT(purchase_status='bought') as number_bought 
  FROM Purchases
  JOIN Items ON Purchases.item_id=Items.item_id
  GROUP BY Items.item_id
  </code></pre>
  
  <p>Here's my DB structure:</p>
  
  <pre><code>Table Items
  item_id item_name
  1           item_1
  2           item_2
  3           item_3
  
  Table Purchases
  item_id  purchase_status    user_name
  1           bought          joe
  2           bought          joe
  1           bought          tom
  1           bought          bill
  </code></pre>
  
  <p>Desired result for <code>tom</code></p>
  
  <pre><code>item_id item_name number_bought did_i_buy
  1        item_1         3        yes
  2        item_2         1        no
  </code></pre>