MYSQL GROUP BY查询,结果只取最新一条记录

mysql 用 group by 查询时,会自动保留   对应组 ‘最先搜索出来的数据’,但这时数据可能不是最新的

如何设置保留 对应组‘最后搜索出来的数据’ 呢?详见代码

   

对于mysql 5.5版本

select * from (
    
    select * from table_name order by create_time desc

) as t
group by t.id;
EOT;

   

对于mysql 5.7版本,需要加入limit限制,否则不生效

select * from (
    
    select * from table_name order by create_time desc limit 100000

) as t
group by t.id;
EOT;

你可能感兴趣的:(mysql)