Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT *
- FROM
- channels
- JOIN gigs ON channels.id = gigs.channel_id
- JOIN songs ON gigs.song_id = songs.id
- JOIN (
- SELECT
- t1.channel_id,
- t1.song_id,
- COUNT(t2.song_id) AS theCount
- FROM gigs t1
- LEFT JOIN gigs t2 ON t1.channel_id = t2.channel_id AND t1.song_id > t2.song_id
- GROUP BY t1.channel_id, t1.song_id
- HAVING theCount < 2
- ) AS dt USING (channel_id, song_id);
- ;
Add Comment
Please, Sign In to add comment