mysql中的去重

2021-09-26 20:22:47 字數 402 閱讀 1880

關於 distinct 關鍵字

select distinct uid, name from zzzz;
其真正的意思是去掉重複的記錄,先select uid, name from zzzz;然後過濾掉重覆記錄,保留第一條記錄。所以,dinstinct的結果取決於你查詢的字段,它並不是過濾掉某個字段。

如果我們只需要過濾掉重複的 uid 呢?

select uid, name from zzzz group by uid;
或者過濾掉重複的 uid, name

select uid, name, age from zzzz group by uid, name;

mysql去重欄位 mysql多字段去重,並計數

問 題 mysql版本5.5.42 有兩個表,表結構與資料如下 1 goods表 create table goods id int 10 unsigned not null,product varchar 180 collate utf8mb4 unicode ci not null,size v...

mysql 去重方式

distinct group by 不能與order by一起使用,細節看執行計畫 exists 某些地方推薦,資料越多越好用 對下面這條語句去重,查詢資料多時優化,資料多不推薦 select 1 from a r a left join t a m b on a.id b.pid left joi...

mysql 查詢 去重

insert into material id file url select id,ekm.file url from extmaterial as ekm left join select file url from material where id id as pm on pm.file u...