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
 General SQL Server Forums
 New to SQL Server Programming
 simple sql

Author  Topic 

actuary
Starting Member

23 Posts

Posted - 2008-11-05 : 07:39:53
Hi, I have a table with this kind of data

Name Val
aaa 1
aaa 2
bbb 3
aaa 3
aaa 4
bbb 4

I just need to get the records where its
((Val=1 or Val=2) AND (Val=3 or Val=4)), in the above case it would only be aaa.

Need help!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-05 : 07:44:21
[code]SELECT Name
FROM Table
GROUP BY Name
HAVING SUM(CASE WHEN Val=1 OR Val=2 THEN 1 ELSE 0 END)>0
AND SUM(CASE WHEN Val=3 OR Val=4 THEN 1 ELSE 0 END)>0[/code]
Go to Top of Page

actuary
Starting Member

23 Posts

Posted - 2008-11-05 : 08:01:45
you simply ROCK sir! thankssss!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-05 : 08:03:05
Cheers
Go to Top of Page
   

- Advertisement -