Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MYSQL include NULL in query

Tags:

sql

mysql

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

I migrated servers recently and on the previous server this statement included ALL records between $upper and $lower.

The new server excludes the NULL records between $upper and $lower.

Incomplete orders are saved consecutively without order_number(s); and a NULL value.

I assume there is a setting in the MYSQL.conf file. Or I am using a different version of MYSQL that no longer supports automatically including the NULL value in a query.

like image 340
Jeff Avatar asked Nov 04 '25 16:11

Jeff


1 Answers

I have no idea why the old server included null values as that would violate a fundamental rule about how comparison to nulls should work. If you want nulls your query should be something like:

Select ...
From orders
Where ( order_number >= $lower And order_number <= $upper )
    Or order_number Is Null
like image 159
Thomas Avatar answered Nov 07 '25 06:11

Thomas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!