Mysql not selecting null values [duplicate]

筅森魡賤 提交于 2019-12-25 03:45:43

问题


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:


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)


来源:https://stackoverflow.com/questions/34664944/mysql-not-selecting-null-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!