Jay Roy
asked on
db2 != check
Dear experts
I have a table CUSTOMER with column ID and NAME
Table: CUSTOMER
ID NAME
1 Eric
3 [Null]
I have a simple query to retrieve data where NAME is not 'Eric'
select * from CUSTOMER where NAME != 'Eric'
i am expecting to see
3 [Null]
but it doesnt return anything.
any clue?
I have a table CUSTOMER with column ID and NAME
Table: CUSTOMER
ID NAME
1 Eric
3 [Null]
I have a simple query to retrieve data where NAME is not 'Eric'
select * from CUSTOMER where NAME != 'Eric'
i am expecting to see
3 [Null]
but it doesnt return anything.
any clue?
ASKER
>>select * from CUSTOMER where NAME <> 'Eric'
nope, already tried that but still doesn't work.
thanks
nope, already tried that but still doesn't work.
thanks
is the "ID" field an actual entered field or is it an identity field?
ASKER
when I do
select * from CUSTOMER where NAME = 'Eric'
I see one row, so I am really confused why != doesn't work.
select * from CUSTOMER where NAME = 'Eric'
I see one row, so I am really confused why != doesn't work.
ASKER
>>>is the "ID" field an actual entered field or is it an identity field?
ID and NAME are just a VARCHAR fields , no identity field in the table.
ID and NAME are just a VARCHAR fields , no identity field in the table.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
something like this works
select * from CUSTOMER where NAME != 'Eric' or name is null
but is that guaranteed to work is my concern.
I just want to return everything whose NAME is not Eric.
select * from CUSTOMER where NAME != 'Eric' or name is null
but is that guaranteed to work is my concern.
I just want to return everything whose NAME is not Eric.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The root issue withOUT the "or name is null" is that you can't evaluate null against a condition. Something either is, or is not, null. It cannot be compared to any specific value.
In conclusion, if you need the null results you simply have to include that extra bit of code.
In conclusion, if you need the null results you simply have to include that extra bit of code.
A null is neither equal nor not equal. It's... null. That is, a value doesn't exist in that column in that row. If it doesn't exist, a comparison doesn't make logical sense.
ASKER
thanks all.
Hi!
You could do a query like this
This would give you the names that are in the column NAME excluding the name Eric and
report all rows that are NULL with 'A EMPTY FIELD' string.
Note that a NULL value indicates that a particular value for a certain column in a certain row is missing.
Regards,
Tomas Helgi
You could do a query like this
select coalesce(NAME , 'A EMPTY FIELD') NAME from CUSTOMER where NAME <> 'Eric' ;
This would give you the names that are in the column NAME excluding the name Eric and
report all rows that are NULL with 'A EMPTY FIELD' string.
Note that a NULL value indicates that a particular value for a certain column in a certain row is missing.
Regards,
Tomas Helgi
I know they're supposedly both the same thing, but curious if there is some logic that might make one different.
Open in new window