Mysql not selecting null values [duplicate]

2019-09-17 18:14发布

This question already has an answer here:

I have the following query:

SELECT * FROM table 
WHERE orderdate >= "2015-12-01" 
    AND orderdate <= "2015-12-31" 
    AND values > 0 
    AND orders <> 'Returned'

The problem is that the query doesn't return the rows where the orders column is NULL and I can't figure out why.

1条回答
Bombasti
2楼-- · 2019-09-17 18:57

This is the sql language. Mysql doesn't consider NULL as value. So if you want to include NULL we must specify that.

SELECT * FROM table 
WHERE orderdate >= "2015-12-01" 
    AND orderdate <= "2015-12-31" 
    AND values > 0 
    AND (orders <> 'Returned' or orders is null)
查看更多
登录 后发表回答