2010-12-08 64 views
1

此:mysql刪除語法與select有什麼不同?

SELECT * 
    FROM tbl_playlists, tbl_playlistsongs 
WHERE tbl_playlists.playlist_id = tbl_playlistsongs.playlist_id 
    AND tbl_playlists.playlist_id = 1 

...作品沒有問題。但是:

DELETE from tbl_playlists, tbl_playlistsongs 
WHERE tbl_playlists.playlist_id = tbl_playlistsongs.playlist_id 
    AND tbl_playlists.playlist_id = 1 

...說我有一個語法錯誤。除了SELECT *與DELETE之外,它們是相同的。它對我來說仍然是完美的邏輯意義..但我必須錯過一些東西!

回答

4

傳統SQL不支持多表刪除,但MySQL 確實是。這意味着你使用MySQL特定的語法:

DELETE pl, pls 
    FROM TBL_PLAYLISTS pl 
    JOIN TBL_PLAYLISTSONGS pls ON pls.playlist_id = pl.playlist_id 
WHERE pl.playlist_id = 1 

參考:

+0

有趣的是,從來不知道MySQL的支持加入刪除。 – 2010-12-08 03:53:36