這個是SQL中distinct的典型用法:
1)從字面意思就可以了解到:
distinct
[dis'tiŋkt]
adj.
明顯的;獨特的;清楚的;有區別的
2)在SQL中用distinct來消除重復出現的欄位值。
使得每個欄位值只出現一次。
具體用法如下:
select
distinct
欄位名
from
表;
distinct
欄位名
意思就是只顯示一次該欄位名
一般情況下和order
by
結合使用,這樣可以提高效率。
所以這個問題的答案是:select
distinct
1,2,3,4
from
表;
1,2,3,4分別代表第一,二,三,四列的欄位名,我猜測可能第一列就是每個人的ID,
這樣你把重復的ID過濾留下一個,估計就是你想要的結果了。
希望我的回答能讓您滿意。
『貳』 sql查詢去掉重復記錄
1、打開要去掉重復數據的資料庫,這里新建一張含有重復數據的user表做示例,如下圖所示:
『叄』 在sql語言中去掉重復值的命令是
distinct。
SQLserver中很明顯的去重復的語句是distinct。selectdistinct是去除重復的記錄行,count(distinctColumn),消除重復值。還有一些不明顯的具有去重功能的詞,例如union,會去除重復的記錄行或值。
『肆』 SQL 怎麼去除完全重復的數據
用SQL語句,刪除掉重復項只保留一條
在幾千條記錄里,存在著些相同的記錄,如何能用SQL語句,刪除掉重復的呢
1、查找表中多餘的重復記錄,重復記錄是根據單個欄位(peopleId)來判斷
select * from people
where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)
2、刪除表中多餘的重復記錄,重復記錄是根據單個欄位(peopleId)來判斷,只留有rowid最小的記錄
delete from people
where peopleName in (select peopleName from people group by peopleName having count(peopleName) > 1)
and peopleId not in (select min(peopleId) from people group by peopleName having count(peopleName)>1)
3、查找表中多餘的重復記錄(多個欄位)
select * from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
4、刪除表中多餘的重復記錄(多個欄位),只留有rowid最小的記錄
delete from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
5、查找表中多餘的重復記錄(多個欄位),不包含rowid最小的記錄
select * from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
6.消除一個欄位的左邊的第一位:
update tableName set [Title]=Right([Title],(len([Title])-1)) where Title like '村%'
7.消除一個欄位的右邊的第一位:
update tableName set [Title]=left([Title],(len([Title])-1)) where Title like '%村'
8.假刪除表中多餘的重復記錄(多個欄位),不包含rowid最小的記錄
update vitae set ispass=-1
where peopleId in (select peopleId from vitae group by peopleId
『伍』 SQL中如何刪除重復數據
select
欄位1,欄位2,欄位3
from
table
group
by
欄位1,欄位2,欄位3
having
count(*)>1
用上邊這句能找出所有重復的數據
欄位1,2,3你替換成你表裡的欄位名,如果有更多欄位的話,你就繼續添加,最後group
by的時候不要忘記了
刪除的時候要建立一個臨時表
create
table
new_table
as
select
欄位1,欄位2,欄位3
from
old_table
group
by
欄位1,欄位2,欄位3;
然後刪除原表數據
truncate
table
old_table;
然後把臨時表數據反插回去
insert
into
new_table
select
*
from
old_table;
『陸』 sql如何刪除重復數據
sql查詢去除重復值語句
sql 單表/多表查詢去除重復記錄
單表distinct
多表group by
group by 必須放在 order by 和 limit之前,不然會報錯
************************************************************************************
1、查找表中多餘的重復記錄,重復記錄是根據單個欄位(peopleId)來判斷
select * from people
where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)
2、刪除表中多餘的重復記錄,重復記錄是根據單個欄位(peopleId)來判斷,只留有rowid最小的記錄
delete from people
where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)
and rowid not in (select min(rowid) from people group by peopleId having count(peopleId )>1)
3、查找表中多餘的重復記錄(多個欄位)
select * from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
4、刪除表中多餘的重復記錄(多個欄位),只留有rowid最小的記錄
delete from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
5、查找表中多餘的重復記錄(多個欄位),不包含rowid最小的記錄
select * from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>
『柒』 sql怎麼刪除重復數據
你可以先把重復的數據找出來(SELECT columnName,count(1) as 'count' FROM Table group by columnName HAVING count(columnName)>1),作為唯一數據先備份到臨時表中,
然後再刪除所有重復的數據(DELETE FROM Table where columnName in (SELECT columnName FROM Table group by columnName HAVING count(columnName)>1)),
最後將臨時表中備份的唯一數據放回原表中。
註:如果表中有(所有列)完全重復的數據,那說明你的表創建的有問題,缺少主鍵。你應該學習一下創建數據表的三範式。
『捌』 SQL語句怎麼刪除重復的數據
刪除重復的數據
delete
from
tb
where
id
not
in
(
select
id
from
(select
fileSize,fileName
,max(id)
id
from
tb
group
by
filesize,filename
)
a
)
現在完成了重復數據的刪除,主要是利用了找出某個分組中最大的那個id,其中包括了所有不重復的id,然後使用not
in將需要保留的排除。
『玖』 sql去除重復的項
distinct
b,a,c
------是將b
a
c完全相的記錄只取一條,你的數據里根本沒有完全相同的記錄,所以會全部輸出;
你要的數據可以用下面的sql
select
*
from
(select
t.*,row_number()
over(partition
by
b
order
by
b)
numid
from
table
t)
a
where
a.numid=1;