I have two tables.
Resource:
md5 (PK), link, title
Tags:
md5 (FK), category
it is a one to many relationship such that a resource can have a number of tags.
I want to be able to extract a resource that has both tags, for e.g. a resource that contains the tag ‘web’ and ‘blog’ in it. If I use ‘OR’, it will obviously return even document that contain only ‘web’ or only contain ‘blog’, but if I use AND, I get no results even though I know there are resources that contain both tags
SELECT DISTINCT tags.MD5, Resource.Title, Resource.Link, tags.Category
FROM Resource
INNER JOIN tags ON Resource.MD5 = tags.MD5
WHERE
(tags.Category = @tag)
OR
(tags.Category = @tag2)
ORDER BY tags.MD5
You want to do like that: