如何刪除資料庫中相同的記錄其中的一條,但要保留一條資料

時間 2021-10-14 22:23:54

1樓:匿名使用者

建議這樣做,比較簡單,給表加一個id欄位,預設自增,這樣不會影響表的其他結構,然後寫這樣的sql:

delete from demo where id in (select id from demo where id <> (select top 1 id from demo where name = 'name' and age = 'age') and name = 'name' and age = 'age')

雖然沒測試,不過感覺肯定可行!只是個建議,呵呵!

2樓:匿名使用者

select * from demo

mysql資料庫中多條重複資料,如何只刪除一條?

3樓:蒯淑蘭費琬

這個需要分情況。

1,你的資料庫表中有主鍵,且主鍵上面的資料為唯一值。也就是沒有重複值。

那麼你在刪除的時候,將這個唯一值作為條件進行刪除。

如:delete

from

[表名]

where

id=1

2.所有的資料相同,那麼你只能開啟資料表,手工選定其中某一條,進行刪除。

4樓:初懷雨步申

這條語句寫的太亂了吧.....

delete

from

customers_basket

where

id=(select

cb.id

from

orders

o,orders_products

op,customers_basket

cbwhere

o.orders_status=4

andop.orders_id

=o.orders_id

andop.products_id

=cb.products_id

andcb.customers_id

=o.customers_id);試一下

oracle資料庫查詢去除重複的記錄,保留其中的某一條

5樓:匿名使用者

select 賬號,戶名,開戶行,是否公有,使用者id

from a

where a.id in ('000001','000002',...) -- id引數條件

and a.是否公有='私有'

union -- 與union all不同的是union 會自動去重複

select 賬號,戶名,開戶行,是否公有,使用者id

from a

where a.id in ('000001','000002',...) -- id引數條件

and a.是否公有='公有'

and a.id not in (select id from a where a.是否公有='私有')

SQL Server裡如何刪除資料庫

工具 材料 以win7電腦 sql server management studio為例。1 首先點選電腦左下方 開始 圖示。2 然後在該介面中,點選 sql server management studio 選項。3 之後在該介面中,點選左側 資料庫 選中 要刪除的資料庫 4 接著在該介面中,右鍵...

如何恢復資料庫表刪除資料mysql

以下情況可以恢復資料 1 innodb引擎表開啟了事務,執行dml語句,比如delete update insert之類,並且沒有提交即commit操作的話,可以執行rollback進行回滾恢復。如果是ddl操作,如drop create alter之類的操作時無效的 2 在進行刪除操作之前有備份,...

access資料庫 如何用SQL語句刪除資料

delete from msg sentbox where sendtime 試試。access 時間要用 包起來的。access資料庫的sql語句語法有一點點不一樣,時間是用 括起來的,sqlserver用單引號。delete from msg sentbox where sendtime 日期不...