开发者

How does mysql delete syntax differ from select?

开发者 https://www.devze.com 2023-01-29 04:17 出处:网络
This: SELECT * FROM tbl_playlists, tbl_playlistsongs WHERE tbl_playlists.playlist_id = tbl_playlistsongs.playlist_id

This:

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

...works no problem. But:

DELETE from tbl_playlists, tbl_playlistsongs 
 WHERE t开发者_C百科bl_playlists.playlist_id = tbl_playlistsongs.playlist_id 
   AND tbl_playlists.playlist_id = 1

...says I have a syntax error. They're identical other than the SELECT * vs DELETE. It still makes perfect logical sense to me.. but I must be missing something!


Traditional SQL doesn't support multi-table deletions, but MySQL does. That means you're using MySQL specific syntax:

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

Reference:

  • DELETE (MySQL documentation)
0

精彩评论

暂无评论...
验证码 换一张
取 消