phpMyAdmin
 sql >> Base de données >  >> Database Tools >> phpMyAdmin

Comment obtenir le même résultat en utilisant Mysql Joins au lieu de sous-requêtes imbriquées ?

Vous pouvez modifier votre requête en tant que,

Pour toutes les chansons de la base de données sauf celles de votre 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')";

Ceux de votre 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'";