0

In addition of Magento 2 How to set group by in Collection query?

I have below query now.

SELECT t1.* FROM messages t1 WHERE t1.id = (select max(id) from messages t2 where t2.posts_id = t1.posts_id and t2.from_user_id = t1.from_user_id)

How can i convert it to Magento format as given answer

$collection = $this->collectionFactory->create()
           ->addFieldToFilter('id', $id)
           ->addFieldToFilter('status', 'Enable');

$collection->getSelect()->group('posts_id')->order('id DESC');
2

0

Your Answer

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

Browse other questions tagged or ask your own question.