This is my query:

SELECT `main_table`.* ,
  CONCAT (`main_table`.`name`, " (", count(*), "x)") as `total`
FROM `sales_flat_order_item` AS `main_table`
WHERE (`order_id` = '145375')
GROUP BY `main_table`.`name`

This is my collection right now:

$orderItems = Mage::getModel('sales/order_item')->getCollection()
            ->addFieldToFilter('order_id', $row->getData('entity_id'));

I want to add the concat condition and group by condition. How can I do that ? thx

1 Answer 1


You can do it this way, after your collection code add:

$orderItems->getSelect()->columns(array('total' => 'concat(name, " (", count(*), "x)")'));
  • thx a lot ! it works Oct 26, 2016 at 6:48

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.