mysql中的多个DELETE不能使用别名

时间:2013-04-12 12:23:45

标签: mysql sql sql-delete

我将此方案用于多个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 = ?;

我只获得正常的语法错误。

1 个答案:

答案 0 :(得分:2)

实际上,您只需要使用ALIAS关键字后面的DELETE名称。

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 = ?;