title: Filter product collection on two categories Magento 1.7
body: <p>I want to get a product collection with products in Category A or Category B. I have been able to succesfully get these products with the following php-code:</p>
  
  <pre><code>$collection = Mage::getModel('catalog/product')
      -&gt;getCollection()
      -&gt;joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
      -&gt;addAttributeToFilter('category_id', array('in' =&gt; array('finset' =&gt; 4,19)))
      -&gt;addAttributeToSelect('*');
  </code></pre>
  
  <p>However, if the product is in both category 4 AND 19, then an error is displayed:</p>
  
  <pre><code>Item (Mage_Catalog_Model_Product) with the same id "173" already exist
  </code></pre>
  
  <p>This is because the collection has a duplicate row in it. I'm struggling to find the right code to filter out any duplicate rows in the collection. The solution must be to group the values, or use distinct, but I'm not sure how to go forth.</p>
  
  <p>See also <a href="https://stackoverflow.com/questions/4511314/filter-magento-collection-but-not-products-using-distinct">Filter Magento collection but not products, using distinct</a></p>