title: Magento: Get Collection of Order Items for a product collection filtered by an attribute
body: <p>I'm working on developing a category roll-up report for a Magento (1.6) store. </p>
  
  <p>To that end, I want to get an Order Item collection for a subset of products - those product whose unique category id (that's a Magento product attribute that I created) match a particular value.</p>
  
  <p>I can get the relevant result set by basing the collection on catalog/product.</p>
  
  <pre><code>$collection = Mage::getModel('catalog/product')
  -&gt;getCollection()
  -&gt;addAttributeToFilter('unique_category_id', '75')
  -&gt;joinTable('sales/order_item', 'product_id=entity_id', array('price'=&gt;'price','qty_ordered' =&gt; 'qty_ordered'));
  </code></pre>
  
  <p>Magento doesn't like it, since there are duplicate entries for the same product id.</p>
  
  <p>How do I craft the code to get this result set based on Order Items?  Joining in the product collection filtered by an attribute is eluding me. This code isn't doing the trick, since it assumes that attribute is on the Order Item, and not the Product. </p>
  
  <pre><code>$collection = Mage::getModel('sales/order_item')
  -&gt;getCollection()
  -&gt;join('catalog/product', 'entity_id=product_id')
  -&gt;addAttributeToFilter('unique_category_id', '75');
  </code></pre>
  
  <p>Any help is appreciated.</p>