Each song is is either assigned multiple locations or has no locations at all.
Only the songs that either have no locations assigned in the database or have the location assigned to the ones specified below should be pulled from the database.
Hopefully when you understand my query below it will make sense
Code: Select all
SELECT s.* FROM roster_songs AS s
LEFT JOIN roster_songs_locations AS sl ON sl.song_id = s.id
WHERE EXISTS (
SELECT sl2.* FROM roster_songs_locations AS sl2 WHERE s.id != sl2.song_id
) OR (
sl.location_id = '88fb5f94-aaa6-102c-a4fa-1f05bca0eec6'
OR
sl.location_id = '930555b0-a251-102c-a245-1559817ce81a'
)
GROUP BY s.idAny ideas how I can get this to work?