Guest User

Untitled

a guest
May 25th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. SELECT *
  2. FROM
  3. channels
  4. JOIN gigs ON channels.id = gigs.channel_id
  5. JOIN songs ON gigs.song_id = songs.id
  6. JOIN (
  7. SELECT
  8. t1.channel_id,
  9. t1.song_id,
  10. COUNT(t2.song_id) AS theCount
  11. FROM gigs t1
  12. LEFT JOIN gigs t2 ON t1.channel_id = t2.channel_id AND t1.song_id > t2.song_id
  13. GROUP BY t1.channel_id, t1.song_id
  14. HAVING theCount < 2
  15. ) AS dt USING (channel_id, song_id);
  16. ;
Add Comment
Please, Sign In to add comment