Php sql DISTINCT行id没有重复

时间:2016-08-23 19:07:52

标签: php mysql sql

SELECT DISTINCT buyer,caseid,subject,service FROM s_support  
ORDER BY id DESC

结果是

buyer               subject          service    caseid
abel@gmail.com ---- I need help ---- Other ---- 438613
bani@gmail.com ---- Urgent      ---- Other ---- 438612
rony@gmail.com ---- Help        ---- Other ---- 438611

我想在DISTINCT中查看id如何?我想隐藏重复项,以便每个买家/主题/服务/案例只保留一行,但保留行ID。

id  buyer               subject          service    caseid
9   abel@gmail.com ---- I need help ---- Other ---- 438613
7   bani@gmail.com ---- Urgent      ---- Other ---- 438612
6   rony@gmail.com ---- Help        ---- Other ---- 438611

1 个答案:

答案 0 :(得分:1)

问题尚不清楚,但你可能正在寻找这个。

尝试mysql_query()中的两个并保留适合您需要的那个(如果有的话)

消除重复并保持最低ID

     SELECT MIN(id) AS id, buyer,caseid,subject,service 
     FROM s_support 
     GROUP BY buyer,caseid,subject,service
     ORDER BY id DESC

消除重复并保留最高ID

     SELECT MAX(id) AS id, buyer,caseid,subject,service 
     FROM s_support 
     GROUP BY buyer,caseid,subject,service
     ORDER BY id DESC

如果没有,请以可理解的方式重写该问题:)