sql - MySQL comparison with null value -
i have column called code in mysql table can null. have rows code='c' want ignore in select result set. can have either code=null or code!='c' in result set.
the following query not return row code null:
select * table code!='c'
but query works expected , know right way it.
select * table code null or code!='c'
my question why having code!='c' not return rows code=null? 'c' not null. comparing no value character here. can throw light why doesn't work way?
in mysql, null
considered 'missing, unknown value', opposed no value. take at mysql reference on null.
any arithmetic comparison null
not return true or false, returns null
instead., so, null != 'c'
returns null
, opposed returning true.
any arithmetic comparison 'null' return false. check in sql:
select if(null=123,'true','false')
to check null
values need use is null
& is not null
operator.
Comments
Post a Comment