I want to turn the SQL below into a Zend Db query.

Select * from catalog_product_entity where entity_id not in ( select Distinct(product_id) from sales_flat_order_item)

Can anyone help me with this, I am currently new to magento and it still confuse me. Any help is appreciated.

1 Answer 1


Try this:

    $collection = Mage::getResourceModel('catalog/product_collection');

    $subQuery = $collection->getConnection()->select()
        ->from($collection->getTable('sales/order_item'), 'product_id')

        ->where('e.entity_id NOT IN (?)', $subQuery);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.