question

poornima.narayanan avatar image
poornima.narayanan asked

Check all records in a group for same value

This is my dataset . ***Output :*** I want all records for a single PID which has all records with Active=0. For eg: PID=1 ,we have 2 records where Active=1 (PID=1,CID=2 and CID=3) SO we should ignore this record Our output should only be :PID=3 as all records for this PID has ACTIVE=0 PID CiD Active 1 1 0 1 2 0 1 3 1 1 4 1 2 1 1 2 2 1 2 3 1 2 4 1 2 5 1 3 1 0 3 2 0 3 3 0 4 5 1 4 7 1 4 8 1
sql-server-2008
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
ThomasRushton avatar image
ThomasRushton answered
So you want to select distinct PIDs where there isn't a row where Active = 1? SELECT DISTINCT PID FROM MyTable WHERE PID NOT IN (SELECT PID FROM MyTable WHERE Active=1) Rough guess.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.