如何在查找B.R = 1的所有匹配时,将两个字段A.P和A.C与表B的B.P和B.C进行比较时,如何从表A中删除?
实际上以下任何一项工作都没有,但它应该朝着方向发展,遗憾的是我无法弄清楚如何......
DELETE FROM A WHERE (A.P = B.P AND A.C = B.C where B.C = 1)
DELETE FROM A WHERE (SELECT B.P, B.C FROM B WHERE B = 1)
答案 0 :(得分:4)
DELETE FROM A
FROM A INNER JOIN B ON A.P = B.P AND A.C = B.C
WHERE B.C = 1
双重FROM有时会让人失望。
答案 1 :(得分:2)
DELETE
FROM A
WHERE EXISTS
(
SELECT NULL
FROM b
WHERE b.p = a.p
AND b.c = a.c
AND b.r = 1
)
答案 2 :(得分:1)
DELETE FROM A WHERE A.Id IN
(SELECT A.Id FROM A INNER JOIN B ON A.P = B.P WHERE B.C = 1)
答案 3 :(得分:0)
您要求删除A中的所有记录 那个C值=表B中行中的C值,C = 1且P值相同?
这与删除A中具有C值= 1 [和表B中的相同P值]中的所有行相同。
所以试试这个:
Delete A
Where C = 1
And Exists
(Select * From B
Where C = 1
And P = A.P)
答案 4 :(得分:0)
这样的事情会起作用
DELETE FROM A
FROM A
INNER JOIN B ON A.P = B.P AND A.C = B.C AND B.R = 1