MYSQL在查询中包含NULL

时间:2011-09-07 17:41:38

标签: mysql sql

$sql = "SELECT * FROM orders WHERE order_number>=$lower AND order_number<=$upper";

我最近迁移了服务器并on the previous server this statement included ALL records between $upper and $lower.

新服务器excludes the NULL records between $upper and $lower

不完整订单连续保存,没有order_number;和一个NULL值。

我假设MYSQL.conf file中有一个设置。或者我使用的是不同版本的MYSQL,它不再支持自动包含查询中的NULL值。

1 个答案:

答案 0 :(得分:5)

我不知道为什么旧服务器包含空值,因为这会违反有关如何与空值进行比较的基本规则。如果你想要空值,你的查询应该是这样的:

Select ...
From orders
Where ( order_number >= $lower And order_number <= $upper )
    Or order_number Is Null