I would be glad if somebody could help me solve this problem. I have a music database. There are 3 tables:
album (id, album_name)
album_has_song (album_id, song_id)
song (id, song_name)
I inserted a song to an album (filled in all 3 tables), but now I would like to find an easy way to delete everything when I delete certain album.
$query1 = mysql_query("DELETE FROM album_has_song WHERE album_id=$albumID");
$query2 = mysql_query("DELETE FROM album WHERE id=$albumID");
$query3 = mysql_query("DELETE FROM song JOIN album_has_song ON song.id=song_id WHERE album_id=$albumID AND SELECT EXISTS(SELECT * FROM song JOIN album_has_song ON song.id=song_id WHERE album_id=$albumID)");
$query1
and $query2
works without any problems. Now $query3
.. I would like to check if album has any songs and after that delete all songs that are on the certain album.