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 |
|
sqldev6363
Yak Posting Veteran
54 Posts |
Posted - 2012-03-07 : 11:41:24
|
| ID Code1 A1 B1 A1 C2 A2 A2 B3 C3 C3 BIn the above sample data i need a query to get the output like this.If i want to pick the IDs which are having the Code ONLY A And B. I dont need if the ID is having the Code A,B and C also.Query should give the result only the ID 2.ID Code2 A2 A2 BThanks in Advance.dev |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-03-07 : 12:34:04
|
| [code]SELECT IdFROM YourTableGROUP BY IDHAVING COUNT(DISTINCT code) = 2 AND COUNT( DISTINCT CASE WHEN code IN ('A','B') THEN code END) = 2;[/code] |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|
|