Trouble with DELETE JOIN
DELETE FROM Books INNER JOIN (Classes, Class_Books) O开发者_如何学GoN (Books.ISBN = Class_Books.ISBN AND Class_Books.Class_ID = Classes.Class_ID AND Classes.Term_ID = 63) WHERE Year = '""'
Gives Error: #1064 - You have an error in your SQL syntax;
Replacing DELETE with SELECT it works fine though
Try the following, which will delete records in books that have a 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
In SQL, you say
DELETE FROM
not
DELETE * FROM
even though it's
SELECT * FROM
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 = '""'
精彩评论