如何在 Oracle SQL 上使用内部联接删除记录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41285390/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to delete a record using inner join on Oracle SQL?
提问by Chinovski
I have 3 tables
我有3张桌子
Table A :
表一:
| id_A | Data ... |
Table B :
表乙:
| id_B | Data ... |
Join A_B
加入 A_B
| id_A | id_B |
Those tables are an example of my situation. Well, I am trying to delete many records from Join A_B depending on many conditions like the name of A is X and name of B is Y.
这些表是我的情况的一个例子。好吧,我正在尝试根据许多条件从 Join A_B 中删除许多记录,例如 A 的名称是 X,B 的名称是 Y。
When I execute a SELECT it works, but with DELETE It doesn't.
当我执行 SELECT 时,它可以工作,但 DELETE 则不行。
This is my resquest:
这是我的要求:
DELETE A_B FROM A
INNER JOIN A_B
ON (A.ID = A_B.A_ID)
INNER JOIN B
ON (B.ID = A_B.B_ID)
WHERE B.NAME IN ('X', 'Y')
AND A.NAME = 'Z';
It says :
它说 :
Erreur SQL : ORA-00933: SQL command not properly ended
00933. 00000 - "SQL command not properly ended"
回答by Stephen
回答by JohnHC
Try:
尝试:
delete from A
where A.ID in
(
select A_ID
from A_B
inner join B
on B.ID = A_B.B_ID
where B.NAME in (...)
)
and A.NAME = 'Z'