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

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

图片转代码服务由CSDN问答提供 功能建议

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

结果是

 买方主题服务caseid 
abel@gmail.com ----我需要帮助----其他 ---- 438613 
bani@gmail.com ----急----其他---- 438612 
rony@gmail.com ----求助----其他---- 438611 
 <  / code>  
 
 

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

  id买方主题服务caseid 
9 abel @ gmail。  com ----我需要帮助----其他---- 438613 
7 bani@gmail.com ----紧急----其他---- 438612 
6 rony@gmail.com ---  - 帮助----其他---- 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 :)

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题