如何使用两列从关系 table 中删除一行

How to delete a row from a relationship table using two columns

我正在尝试删除 table T2 和 table T1 上的 T3 之间的关系。 我已经搜索过,但我只能找到只有一个 INNER JOIN 的 DELETE 示例。

我正在尝试类似的操作,但出现错误:

SQL error: ORA-00933. 00000 - "SQL command not properly ended"

DELETE t1
FROM T1 t1
INNER JOIN T2 t2
  ON t2.ID = t1.ID_t2
INNER JOIN T3 t3  
  ON t3.ID = t1.ID_t3
  WHERE (t3.property1 IN 'XXX' AND 
        t3.property2 = 1 AND 
        t2.property = 'YYY');

我怎样才能让它工作?

您正在使用 MySql 语法从 Oracle 数据库中删除。
你可以用 EXISTS:

DELETE FROM T1 
WHERE EXISTS (SELECT 1 FROM T2 WHERE T2.property = 'YYY' AND T2.ID = T1.ID_t2)
  AND EXISTS (SELECT 1 FROM T3 WHERE T3.property1 = 'XXX' AND T3.property2 = 1 AND T3.ID = T1.ID_t3)

这不是有效的 Oracle 语法。尝试 exists:

    DELETE FROM T1 
    where exists 
               (select * from T2 where T2.ID = T1.ID_t2 and T2.property = 'YYY')
    and exists (select * from T3 where T3.ID = T1.ID_t3 and T3.property1 IN ('XXX') AND T3.property2 = 1  ) ;

对于单个值,您可以使用 T3.property1 ='XXX' 而不是 T3.property1 IN ('XXX')