DELETE JOIN的问题

时间:2010-08-20 08:15:04

标签: mysql sql join sql-delete

DELETE FROM Books INNER JOIN (Classes, Class_Books) ON (Books.ISBN = Class_Books.ISBN AND Class_Books.Class_ID = Classes.Class_ID AND Classes.Term_ID = 63) WHERE Year = '""'

给出错误:#1064 - 您的SQL语法出错;

用SELECT替换DELETE它可以正常工作

3 个答案:

答案 0 :(得分:1)

在SQL中,你说

DELETE FROM

DELETE * FROM

即使它是

SELECT * FROM

答案 1 :(得分:1)

DELETE FROM Books 
WHERE ISBN IN (Select Class_Books.ISBN from Class_Books, Classes
               WHERE Class_Books.Class_ID = Classes.Class_ID 
                 AND Classes.Term_ID = 63
              )
AND Year = '""'

答案 2 :(得分:1)

请尝试以下操作,这将删除具有Classes.Term_ID = 63的图书中的记录。

DELETE b FROM Books b
    INNER JOIN Class_Books cb ON b.ISBN = cb.ISBN
    INNER JOIN Classes c ON cb.Class_ID = c.Class_ID  
WHERE Year = '""' 
  AND c.Term_ID = 63