Order By before Group By using Eloquent (Laravel)

后端 未结 6 873
无人共我
无人共我 2020-12-03 21:22

I have a \"messages\" table with the following columns

CREATE TABLE `messages` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `fromId` int(11) NOT NULL,
  `toId         


        
6条回答
  •  臣服心动
    2020-12-03 22:07

    This work for me: (you can remove the order by createdAt in case createAt increase along with id)

    DB::select(DB::raw('select * from (select * from messages group by fromId desc) m order by m.createdAt'));
    

提交回复
热议问题