Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Hi,I would like to display the results only if its having two rows under same id in sql server 2005 eg. if CategoryID 1 is is for two different SubCategories like 1 and 2 then show 1 categoryID, If 1 Categoryid is for 1 and not for 2 then dont show 1 categoryid. ids are autogenerated numbersThanks in advanceSachin Hingoleedit: moved to proper forum
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts
Posted - 2009-05-05 : 10:41:05
if its about category id 1 and 2 only, then
select distinct a.CategoryIDfrom yourtable awhere a.SubCategories=1 and exists(select * from yourtable where CategoryID=a.CategoryID and SubCategories=2)
If its just about the count of different sub-categories,
select CategoryID, count(distinct SubCategories)from yourtablegroup by CategoryIDhaving count(distinct SubCategories)>1