NULL values in where clause

后端 未结 6 767
花落未央
花落未央 2020-12-11 02:17

i\'ve got a table \"bla\" like this:

[id]    [name]    [fk]
1       test      4
2       foo       5
3       bar       NULL

if i do the sql

6条回答
  •  忘掉有多难
    2020-12-11 02:53

    NULL is special in that it represents an "unknown" value. This can't be compared to numbers (or any other value for that matter), hence the result -

    Is NULL <> 4? The answer is - don't know. Is 4 different from an unknown value?

    Try this instead:

    SELECT * FROM bla WHERE fk <> 4 OR FK IS NULL
    

提交回复
热议问题