SQL基礎 抑制重複資料

2021-06-19 16:32:57 字數 567 閱讀 3949

抑制重複資料,使用:distinct

表資料如下:

舉例1:查詢表中員工所有的部門資訊:select subdepartment from t_employee

查詢的結果中部門重複了,為了消除這種重複,使用:selectdistinctsubdepartment from t_employee

注意:distinct是對整個結果進行資料重複處理,而不是針對某一列,例如下面的例子的執行結果

舉例2:select distinct subdepartment,subcompany from t_employee

SQL 6 抑制資料重複

如果要檢索公司有哪些垂直部門,那麼可以執行下面的sql語句 select fdepartment from t employee 執行完畢我們就能看到下面的執行結果 fdepartment development development development humanresource human...

sql刪除重複資料

1 建立表 create table dbo test id numeric 18,0 identity 1,1 not null primary key,name varchar 200 collate chinese prc ci as null remark varchar 1024 coll...

SQL去除重複資料

sql中去除完全相同資料可以用distinct關鍵字,任意欄位去重可以用group by,以下面的資料表為例。idname score1小王 512小魏613小張 714小李515小王 51 1.存在兩條完全相同的紀錄,用關鍵字distinct就可以去掉 select distinct from t...