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 :)

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

报告相同问题?

悬赏问题

  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。