10

我已经检查了已回答的问题。但是,解决方案对我不起作用。

DELETE FROM TEST2
INNER JOIN TEST1 on TEST1.FIELD2 = TEST2.FIELD2
WHERE TEST1.FIELD1 = 22;

当我执行此查询时,我在 phpmyadmin 中收到以下错误。

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version 
for the right syntax to use near 'INNER JOIN TEST1 on TEST1.FIELD2 = TEST2.FIELD2' at line 2

我有点累了。我需要帮助。提前致谢。

4

1 回答 1

28

这应该有效:

DELETE T
FROM TEST2 T
INNER JOIN TEST1 on TEST1.FIELD2 = T.FIELD2
WHERE TEST1.FIELD1 = 22;

小提琴演示示例

我认为你也可以这样做IN

DELETE FROM Test2
WHERE Field2 IN (
    SELECT Field2 
    FROM Test1
    WHERE Field1 = 22)
于 2013-02-22T14:28:52.827 回答