关于mysql:INNER JOIN作为SELECT工作,但不作为DELETE工作

INNER JOIN works as SELECT but not as DELETE

本问题已经有最佳答案,请猛点这里访问。

为什么会有语法错误

1
2
3
4
5
DELETE FROM `print_mailing_request` pmr
INNER JOIN `person` p
  ON p.id = pmr.person AND p.email LIKE '%@TEST.COM'
WHERE
pmr.sent_to_fulfiller != 'y'

什么时候可以正确无误地工作?

1
2
3
4
5
SELECT * FROM `print_mailing_request` pmr
INNER JOIN `person` p
  ON p.id = pmr.person AND p.email LIKE '%@TEST.COM'
WHERE
pmr.sent_to_fulfiller != 'y'


您需要告诉delete从哪个表中删除:

1
2
3
4
5
DELETE pmr
    FROM `print_mailing_request` pmr INNER JOIN
         `person` p
         ON p.id = pmr.person AND p.email LIKE '%TEST.COM'
    WHERE pmr.sent_to_fulfiller != 'y';

表别名位于delete语句之后和from之前。我假设这是第一张提到的桌子。


在不使用表别名的情况下,正确的语法如下所示。缺少要从中删除的表名。

1
2
3
4
5
6
DELETE `print_mailing_request`
FROM `print_mailing_request`
INNER JOIN `person`
  ON `person`.id = `print_mailing_request`.person
  AND `person`.email LIKE '%@TEST.COM'
WHERE `print_mailing_request`.sent_to_fulfiller != 'y'