1.存在兩條完全相同的紀錄
這是最簡單的一種情況,用關鍵字distinct就可以去掉
例子: select distinct * from table(表名) where (條件)
2.存在部分字段相同的紀錄(有主鍵id即唯一鍵)
如果是這種情況的話用distinct是過濾不了的,這就要用到主鍵id的唯一性特點及group by分組
例子:
select * from table where id in (select max(id) from table group by [去除重復的字段名列表,....])
3.沒有唯一鍵ID
例子:
select identity(int,1,1) as id,* into newtable(臨時表) from table select * from newtable where id in (select max(id) from newtable group by [去除重復的字段名列表,....]) drop table newtable