phpMyAdmin
 sql >> Datenbank >  >> Database Tools >> phpMyAdmin

Wie kann man dasselbe Ergebnis mit Mysql-Joins anstelle von verschachtelten Unterabfragen erzielen?

Sie können Ihre Abfrage ändern als,

Für alle Songs in der Datenbank außer denen in deiner Playlist

$sql1 = "Select distinct title, artist, album 
from songs where id not in(Select distinct song.id
from songs song inner join playlist playlist 
on playlist.song_id=song.id
inner join playlists playlists 
on playlists.playlist_id=playlist.playlist_id
and playlists.name = '$playlist_name')";

Die auf deiner Playlist,

$sql2 = "Select distinct song.title, song.artist, song.album
from songs song inner join playlist playlist 
on playlist.song_id=song.id
inner join playlists playlists 
on playlists.playlist_id=playlist.playlist_id
and playlists.name = '$playlist_name'";