0

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

2

Try this:

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

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

    $collection->getSelect()
        ->reset(Zend_Db_Select::COLUMNS)
        ->columns('e.entity_id')
        ->where('e.entity_id NOT IN (?)', $subQuery);

Your Answer

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

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