[英]SELECT distinct value in mysql php
如何在MySQL中選擇DISTINCT值
id r_id cat_id
2 3 56
3 3 57
4 3 57
我想要輸出
id r_id cat_id
2 3 56
3 3 57
我正在使用此代碼並獲取r_id和cat_id,但沒有獲取ID我該如何
SELECT DISTINCT(r_id), cat_id FROM rmcat where rid = '123'
使用GROUP BY函數。
select min(id) as id,max(r_id) as r_id,cat_id
from tablename
where rid = '123'
group by cat_id
您為什么不嘗試像這樣將這些字段組合在一起?
select distinct id, r_id, cat_id from rmcat where rid = '123'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.