Follow this, it's really obvious and simple. For some reason, the results differ between queries and approach angles on data subsets. Keep in mind that the field, correct_addr
is a char(1)
field with allowable nulls.
select distinct correct_addr, count(*) from id_rec group by correct_addr;
correct_addr (count(*))
2477
N 80
Y 84013
3 row(s) retrieved.
Ok, so correct_addr
contains 3 distinct values: "N","Y", and either "" or " " or NULL
So now, I try this:
select count(*) from id_rec where correct_addr <> 'N';
(count(*))
84013
What happened to the 2477 records that have that blank value?
Another try from a different angle:
select count(*) from id_rec where correct_addr in (null,'',' ','Y');
(count(*))
84013
Same thing happens....
So what is going on here? Why doesn't the sql engine (?) recognize the blank value in the last 2 sql statements? It discovers it fine in the first query with the grouping, but nowhere else.
Does anyone have any ideas as to why this type of thing happens?