试试这个。我创建了一个包含三列的表tblA 。
CREATE TABLE tblA
(
id int IDENTITY(1, 1),
colA int,
colB int,
colC int
)
并添加了一些重复值。
INSERT INTO tblA VALUES (1, 2, 3)
INSERT INTO tblA VALUES (1, 2, 3)
INSERT INTO tblA VALUES (4, 5, 6)
INSERT INTO tblA VALUES (7, 8, 9)
INSERT INTO tblA VALUES (7, 8, 9)
如果您在下面的语句中将选择替换为删除,您的多列删除将起作用。
SELECT MIN(Id) as id
FROM
(
SELECT COUNT(*) as aantal, a.colA, a.colB, a.colC
FROM tblA a
INNER JOIN tblA b ON b.ColA = a.ColA
AND b.ColB = a.ColB
AND b.ColC = a.ColC
GROUP BY a.id, a.colA, a.colB, a.colC
HAVING COUNT(*) > 1
) c
INNER JOIN tblA d ON d.ColA = c.ColA
AND d.ColB = c.ColB
AND d.ColC = c.ColC
GROUP BY d.colA, d.colB, d.colC