mysql - mysql 中的多个 DELETE 不适用于别名

标签 mysql sql sql-delete

我使用此方案进行多次删除

DELETE Table1, Table2, Table3
FROM   Table1
JOIN   Table2 ON (Table2.ConditionID = Table1.ConditionID)
JOIN   Table3 ON (Table3.ConditionID = Table2.ConditionID)
WHERE  Table1.ConditionID = ?;

为什么我不能使用这样的别名

DELETE Table1, Table2, Table3
FROM   Table1 t1
JOIN   Table2 t2 ON (t2.ConditionID = t1.ConditionID)
JOIN   Table3 t3 ON (t3.ConditionID = t2.ConditionID)
WHERE  t1.ConditionID = ?;

我只得到一个正常的语法错误。

最佳答案

实际上可以,只需使用 DELETE 关键字后面给出的 ALIAS 名称即可。

DELETE  t1, t2, t3
FROM    Table1 t1
        JOIN   Table2 t2 ON (t2.ConditionID = t1.ConditionID)
        JOIN   Table3 t3 ON (t3.ConditionID = t2.ConditionID)
WHERE   t1.ConditionID = ?;

关于mysql - mysql 中的多个 DELETE 不适用于别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15971337/

相关文章:

mysql - SQL根据条件求字段平均值

MySQL外键问题

mysql - SQL:将两列相加为 'Name' 并在 where 中使用该名称

sql - 如何在 Athena (Presto) 中处理上个月的每月间隔?

mysql - 删除 MySQL 中的重复行

sql - 简单的 DELETE 语句不起作用

php - 当列具有相同条目时删除双行

mysql - 如何使用 SELECT INTO OUTFILE 绕过 MySQL Errcode 13?

java - 如何使用 Spring、Hibernate 将具有自动值的数据插入到 createdDate 和 updatedDate?

sql - DB2 11.1 - Unpivot 表并根据条件选择值