Created
July 14, 2011 09:02
-
-
Save smiler/1082131 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Model at http://i.imgur.com/kuxy2.png | |
-- Find all channels that have tags 'tag 1' and 'tag 2' | |
select c.channel | |
from channels c | |
where c.id in (select ct.channelid | |
from channel_tags ct | |
join tags t on ct.tagid = t.id | |
where t.tag = 'tag 1') | |
and c.id in (select ct.channelid | |
from channel_tags ct | |
join tags t on ct.tagid = t.id | |
where t.tag = 'tag 2') | |
select c.channel | |
from channels c | |
join channel_tags ct on c.id = ct.channelid | |
join tags t on t.id = ct.tagid | |
where t.tag in ('tag 1', 'tag 2') | |
group by c.channel, | |
ct.channelid | |
having count(ct.channelid) = 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment