Henok Henok - 3 months ago 13
SQL Question

Php sql DISTINCT row id without duplicate

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

Answer

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