dongyirong3564 2016-08-23 19:07
浏览 65
已采纳

Php sql DISTINCT行id没有重复

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

result is

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

I want to view id in DISTINCT How? I wants to hide the duplicates to keep only one row per buyer/subject/service/case but keep a row 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条回答 默认 最新

  • dtz63853 2016-08-23 19:39
    关注

    The question is unclear but you are probably looking for this.

    Try both of those in your mysql_query() and keep the one that fits your need (if any)


    Eliminate duplicates and keep the lowest ID

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

    Eliminate duplicates and keep the highest ID

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

    If not, rewrite that question in an intelligible manner :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面