I've seen a number of solution for INTERSECT in MSSQL 2000 but all the examples I've seen go across two tables.
What I need is to be able to INTERSECT records with multiple criteria from the same table.
For example:
Lsts say I have a BlogPostTag table where I store the BlogPostId and the TagId that pertains to this blog post. Further, a BlogPost can be associated to multiple tags. So I could have a BlogPost associated to the tags C# and ASP.NET.
sample data
I now need a query that will give me the BlogPostIds of all posts that have the TagIds 5 AND 7 (result should be BlogPostIds 1 AND 2)
Give me the BlogPostIds of all posts that have the TagIds 5 AND 6 AND 7. The result should be BlogPostId 1 only.
I hope that makes sense.
What I need is to be able to INTERSECT records with multiple criteria from the same table.
For example:
Lsts say I have a BlogPostTag table where I store the BlogPostId and the TagId that pertains to this blog post. Further, a BlogPost can be associated to multiple tags. So I could have a BlogPost associated to the tags C# and ASP.NET.
sample data
Code:
BlogPostId TagId
1 5
1 6
1 7
2 5
2 7
2 8
Give me the BlogPostIds of all posts that have the TagIds 5 AND 6 AND 7. The result should be BlogPostId 1 only.
I hope that makes sense.
Comment