sql - Why does this simple MySQL query not return the row? -
i have row in table users
username test
. reason, though, query returns empty result set.
select `id` `users` `username` = "test" , `id` != null;
however, if remove `id` != null
segment, query returns result id = 1
.
but 1
!= null
. how happening?
the id
field non-nullable , auto-increment.
thanks!
the query doesn't return row because predicate " id != null
" never return true.
th reason boolean logic in sql 3 valued. boolean can have values of true
, false
or null
.
and inequality comparison return null
whenever 1 (or both) of values being compared null
.
the sql standard means compare null use id null
or id not null
. mysql adds convenient null-safe comparison operator return true or false:
col <=> null
. or, in case not (col <=> null)
Comments
Post a Comment