distinct order by 排序问题

时间:2023-03-09 18:45:08
distinct order by 排序问题

使用类似“SELECT DISTINCT `col` FROM `tb_name` ORDER BY `time` DESC”这样的sql语句时,会遇到排序问题。

以上面的sql语句分析:order by 只是针对了获取到的col进行了时间排序,而取到的col则是系统默认排序的。

想要order by起效果,应该使用子查询,”SELECT DISTINCT `col` FROM (SELECT * FROM `tb_name` ORDER BY `time` DESC) AS a“。