BlueMoon1 BlueMoon1 - 1 month ago 9
SQL Question

Return data having value 0

i m a newbie so may be a simple SQL query for you guys, in a table i have records having PFAULT 0 and 1 against one SRID. i want to get only those records which have 0 as PFault. if any record has PFault 1 than i dont need that record
e.g. a record can have both values i.e. 0 and 1 but i need only those records which don't have 1. field type is

bit
.

sample table data

ID | SRID | PFault
---- | ---- | ----
2255 | 1212 | 0
2256 | 1212 | 0
2257 | 1212 | 1
2258 | 1213 | 0
2259 | 1213 | 1
2260 | 1214 | 0
2261 | 1214 | 0
2262 | 1216 | 0


as per above I need data for

SRID 1214 and 1216

hvd hvd
Answer

You almost phrased it in English already in a way that can be translated quite straightforwardly to SQL. That's a very good start. That straightforward translation then looks like:

select srid from table
except
select srid from table where pfault = 1;
Comments