我想通过比较表的两列来删除不匹配的记录?
答案 0 :(得分:0)
请尝试这个。
DELETE FROM @tbl WHERE Column1 != Column2
OR
DELETE A FROM @tbl1 A
LEFT JOIN @tbl2 B
ON A.Id = B.Id
WHERE B.Id IS NULL
答案 1 :(得分:0)
如果要比较两个表:
DELETE FROM Table1
WHERE (COLUMN)
NOT IN
(SELECT Table2.COLUMN FROM Table2,TABLE1 where Table2.COLUMN=TABLE1.COLUMN)
其他:
DELETE FROM Table1 where column1!=column2
答案 2 :(得分:0)
您还可以使用“左联接”删除不匹配的记录。
DELETE t1 FROM @TABLE1 t1
LEFT JOIN @TABLE2 t2 on t1.NAME1 = t2.NAME2
WHERE t2.ID IS NULL