Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Group by number value based on second value

Status
Not open for further replies.

djmousie

Technical User
Oct 10, 2001
164
US
I am trying to extract items in Field 1 based on a criteria in Field 2. For Example, I want the query to only pull back data on the record 1234 since that record has no "Y". However, if I dont want record 123 and 12345 to appear since if you group those numbers, there is a "Y" and an "N", I only want those unique records where there is an "N" only.

Field1 Field2
123 Y
123 N
123 N
1234 N
12345 Y
12345 N

Any help?
 
Something like this ?
SELECT Field1
FROM yourTable A
WHERE Field2 = 'N'
AND Not Exists(SELECT * FROM yourTable B WHERE B.Field1=A.Field1 AND B.Field2='Y')

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Another way:
SELECT Field1
FROM yourTable
GROUP BY Field1
HAVING Max(Field2) = 'N'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top