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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Help creating query!

Author  Topic 

jribeiro
Starting Member

2 Posts

Posted - 2010-11-22 : 11:29:55
Hi there I have a table like:


A | B | C
1 | Chair | Red
2 | Table | Blue
3 | Bed | Red
4 | Table | Red
5 | Chair | Green
6 | Chair | Blue

C is an enum type with the following possible values: "Red", "Blue" and "Green".

I want to test if there is any value B that is used for all the colors C.

In this case, Chair is used with all the colors so the result should be positive.

I have some experience in SQL but I'm a bit clueless here.

Can anyone help?

Thanks

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2010-11-22 : 11:35:10
SELECT B,count (distinct C)
FROM yourTable
GROUP BY B
HAVING count(distinct C) = 3

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

jribeiro
Starting Member

2 Posts

Posted - 2010-11-22 : 11:46:33
Thanks!!!!!! Worked great.

I feel kind of ashamed :) ehheheh sometimes we get locked.

Thanks once again
Go to Top of Page
   

- Advertisement -