2014-06-18 94 views
1

爲什麼這個有語法錯誤INNER JOIN作品SELECT但不是DELETE

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' 

當這正常工作沒有錯誤?

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' 
+0

您是否試圖從兩個表中刪除數據? – Jhecht

+0

因爲一個是SQL Server 2008,而我的是mySQL(標記但沒有明確說明),我不確定該帖子是否與我的相關,而且我試圖實現該解決方案... – jerrygarciuh

回答

3

正確的語法如下所示,而不使用表別名。您缺少要從中刪除的表名。

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' 
5

你需要告訴delete什麼表中進行刪除:

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之前。我假設它是提到的第一張桌子。