获取数据库中多个重复信息最新一条的方法


1.排序加分组。

select id,name,updateTime from (
    select id,name,updateTime 
    from table_user 
    -- 注意这里排序列要符合实际要筛的业务
    order by id,updateTime desc
) t
group by t.id

2.使用唯一标识。

select id,name,updateTime 
from table_user where concat_ws('_', id, updateTime ) in ( select concat_ws('_', id, max(updateTime) ) from table_user group by t.id ) t