List:General Discussion« Previous MessageNext Message »
From:Sebastian Mendel Date:April 22 2008 3:42pm
Subject:Re: SQL question: find items tagged with specific tags
View as plain text  
Ingo Weiss schrieb:
> Hi all,
> 
> I have an application where items can be tagged. There are three tables 
> 'items', 'taggings'  and 'tags' joined together like this:
> 
>  items inner join taggings on (items.id = taggings.item_id) inner join 
> tags on (tags.id = taggings.tag_id)
> 
> Now I have been struggling for some time now with coming up with the SQL 
> to find the items the tags of which include a specified list of tag 
> names. Example:
> 
> I am looking for items tagged with 'blue' and 'red'. This should find me:
> 
> - items tagged with 'blue' and 'red'
> - items tagged with 'blue', 'red' and 'green'

SELECT DISTINCT items.*
FROM [your join above]
WHERE tags.name IN ('blue', 'red');

-- 
Sebastian Mendel
Thread
SQL question: find items tagged with specific tagsIngo Weiss22 Apr
  • Re: SQL question: find items tagged with specific tagsSebastian Mendel22 Apr
    • Re: SQL question: find items tagged with specific tagsIngo Weiss23 Apr
      • Re: SQL question: find items tagged with specific tagsSebastian Mendel23 Apr