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

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -