Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
velnias2010
Posting Yak Master
125 Posts |
Posted - 2011-02-02 : 04:18:22
|
lets say you have 2 queriesselect content_id from tblTest where categoryId = 10select content_id from tblTest where categoryId = 5And I want the content_id which are in both only ? |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-02-02 : 04:44:51
|
select content_id from tblTest t1 where categoryId = 10and exists(select * from tblTest t2 where t2.categoryId = 5 and t2.content_id = t1.content_id) No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-02-02 : 08:53:07
|
If you use versions starting from 2005,select content_id from tblTest where categoryId = 10INTERSECT select content_id from tblTest where categoryId = 5MadhivananFailing to plan is Planning to fail |
|
|
ahmeds08
Aged Yak Warrior
737 Posts |
Posted - 2011-02-03 : 01:31:40
|
select content_id from tbltest where content_id in(10,5) |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-02-03 : 01:42:01
|
quote: Originally posted by ahmeds08 select content_id from tbltest where content_id in(10,5)
I think the OP is looking for contents that have both categories 5 AND 10 ? |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-02-03 : 03:00:32
|
quote: Originally posted by MIK_2008
quote: Originally posted by ahmeds08 select content_id from tbltest where content_id in(10,5)
I think the OP is looking for contents that have both categories 5 AND 10 ?
Yes it is. It is not simple as what ahmeds08 postedMadhivananFailing to plan is Planning to fail |
|
|
|
|
|