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');