SQL去除重複記錄急

2022-03-03 04:04:15 字數 1249 閱讀 7425

1樓:極速love鋒狂

樓主既然只想要booid=1234中的任何一條記錄,那可以這樣:

select top 1 * from bookinfo where booid = '1234'

2樓:

我的辦法是:

例如要清除a表的重複資料;

先暫停伺服器訪問;

select distinct * into b from a;

delete a;

select distinct * into a from b;

drop table b;

呵呵,可能不是好方法,但這樣做也得到了我想要的結果

3樓:匿名使用者

前提是這個表的每一行必須要有一個欄位的值是唯一的,而且是整型,沒有的話最好在結構里加一個,比如這個欄位名是:id

select bookinfo.bookid,bookinfo.bookname,bookinfo.bookauthor from (

select max(id) as maxid,bookid,bookname,bookauthor from bookinfo group by bookid,bookname,bookauthor

) tmp

inner join bookinfo on bookinfo.id=tmp.maxid

sql裡這樣寫應該可以的。

4樓:淡如水

select distinct * from ....

知道你這句的意思嗎 這裡的distinct不是指去除相同bookid的資訊,

而是去除所有相同欄位的資訊。就知道為什麼出現那種結果了例子:

id name

1 a1 b

1 c1 a

結果是:

1 a1 b

1 c注意事項:這裡的兩條重複的記錄千萬不要出現 這只是個例子可以用 select distinct bokkid ,(其他全部欄位..) from ....

5樓:匿名使用者

將select distinct *改成select distinct 具體的欄位試試,

然後網上有很多刪除重複欄位的文章,查下,將重複的刪除,然後為表設定主鍵,這樣以後就不會有完全一樣的記錄了,也就不會造成這樣的麻煩了,

呵呵,希望能有幫助,^_^

6樓:

支援 極速love鋒狂 的

SQL裡面怎麼去除重複的

建議你分步驟做 第一步,select into b from 表 where 1 2 給 b 表增加一個不重複的關鍵字索引 值1 索引然後再 select into b from 表 這樣就過濾掉了 值1 的重複項 第二步,你使用select 值2 count 值1 from 表 group by ...

SQL怎麼去除某一列的重複項

假設存在一個主鍵id,name為重複列 下面這句可以查出所有的沒有重複的資料 select from表as awhere id select min id from 表where name a.name 根據上面這句就可以刪除所有重複項的資料delete from 表where idnot in s...

sql篩選出記錄數大於2的記錄

id重複且大抄 於2select from 表名 where id in select id from 表名 where count id 1 group by id and id 2 id大於2 select from 表名 where id 2 怎麼在sql server中查詢一個表中某個資料重...