从相当大的SQL Server表中删除重复行的最佳方法是什么(即300,000多行)?
当然,由于RowID身份字段的存在,行不会是完美的重复.
MyTable的
RowID int not null identity(1,1) primary key,
Col1 varchar(20) not null,
Col2 varchar(2048) not null,
Col3 tinyint not null
Run Code Online (Sandbox Code Playgroud) 我怎么能unique row id不unique row id存在?
我的桌子是
col1 col2 col3 col4 col5 col6 col7
john 1 1 1 1 1 1
john 1 1 1 1 1 1
sally 2 2 2 2 2 2
sally 2 2 2 2 2 2
Run Code Online (Sandbox Code Playgroud)
我希望在重复删除后留下以下内容:
john 1 1 1 1 1 1
sally 2 2 2 2 2 2
Run Code Online (Sandbox Code Playgroud)
我已经尝试了一些查询,但我认为它们依赖于行ID,因为我没有得到理想的结果.例如:
DELETE
FROM table
WHERE col1 IN (
SELECT id
FROM table
GROUP BY id
HAVING (COUNT(col1) > 1)
)
Run Code Online (Sandbox Code Playgroud) 我想删除基于两列的重复行,但需要保留所有行的1行.
重复行可以超过两行,如,
ID NAME PHONE
-- ---- ----
1 NIL 1234
2 NIL 1234
3 NIL 1234
4 MES 5989
Run Code Online (Sandbox Code Playgroud)
我想从3以上删除2行中的任意一行并保留1行.
我有一个包含大量重复量的数据库,每有一个独特的ID,但它们的PermitID和EncID是相同的.我需要删除数据库中除最高ID之外的所有ID.
sql语句,
DELETE FROM tblInvoices
WHERE EncID = '0237' AND PermitID IN (
SELECT Max(ID) FROM tblInvoices Group BY PermitID)
Run Code Online (Sandbox Code Playgroud)
删除所有记录.我试过了
DELETE FROM tblInvoices
WHERE EncID = '0237' AND PermitID
< (SELECT Max(ID) FROM tblInvoices Group BY PermitID)
Run Code Online (Sandbox Code Playgroud)
但我收到错误
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
数据的一个例子是
ID PermitID EncID
1 …Run Code Online (Sandbox Code Playgroud) 我有一个问题.我有一个有近20亿行的表(是的,我知道......)并且有很多重复数据,我想从中删除它.我想知道怎么做到这一点?
列是:第一个,最后一个,dob,地址,城市,州,邮编,电话,并在一个名为的表中PF_main.谢天谢地,每个记录都有一个唯一的ID,并且它在列中称为ID.
如何重复删除并在pf_main表格中为每个人留下1个唯一的条目(行)?
提前感谢您的回复......
我的数据是:
ID Name date
1 Ben 2017-01-21
2 Mark 2017-01-20
3 Mark 2017-01-21
4 Ell 2017-01-19
Run Code Online (Sandbox Code Playgroud)
应该是
ID Name date
1 Ben 2017-01-21
3 Mark 2017-01-21
4 Ell 2017-01-19
Run Code Online (Sandbox Code Playgroud)
必须删除 ID 为 2 的旧“标记”