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 |
sc22
Starting Member
3 Posts |
Posted - 2015-03-20 : 16:10:46
|
I have a table with the structure below. I'm looking to get all records where the SAME record in eX_ID match all the criteria in category ID.Example: Category_ID = 203 and 204. Would return 'BAR105842'ex_ID category_ID IDBAR105842 203 2BAR105842 204 3BAR105842 210 33BAR105842 230 89BAR105842 234 133FLE10311 260 736FLE10311 261 737FLE10311 268 1775FLE10311 282 1776FLE10311 298 2755XGEN1443 315 3041XGEN1443 343 6267XGEN1443 342 6268XGEN1443 345 6269XGEN1443 341 6270XGEN1443 380 13168XGEN1443 383 13169XGEN1443 412 19312Thanks!! |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2015-03-20 : 16:34:43
|
one way:select * from tablewhere category_ID in (203, 204)and 2 = (select count(*) from tablewhere category_ID in (203, 204)) |
|
|
sc22
Starting Member
3 Posts |
Posted - 2015-03-20 : 16:52:09
|
Thank you for the reply!But that did not return any records. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2015-03-20 : 16:52:59
|
select ex_ID, count(*)from @twhere category_id in (203, 204)group by ex_IDhaving count(*) = 2Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
sc22
Starting Member
3 Posts |
Posted - 2015-03-20 : 17:05:10
|
Thank you that is what I needed! |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|