4
$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.

4
  • which MySQL version number ? Commented Sep 7, 2011 at 17:47
  • 2
    Can't say why the behavior changed (and I'm surprised any version of MySQL could be made to return NULLs with that query), but the new behavior you're seeing is correct and the old behavior is wrong. Commented Sep 7, 2011 at 18:07
  • solution to this - make sure the column is not null Commented Sep 7, 2011 at 18:09
  • MySQL client version: 5.0.77 | Changing the NULL value may work. But the system is running and I cant/wont make changes to test this. Commented Sep 8, 2011 at 15:18

1 Answer 1

9

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
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks. "Or order_number Is Null" returns all NULL values in the database. I want to limit it to the Null records between the values.
@Jeff - What do you mean by limiting the results to the Null rows "between values"? A null order_number isn't "between" anything.
@Jeff - Said another way, if order_number is null, how do would you determine whether a given row with a null order_number should or should not appear in the resultset? Remember that tables are collections of unordered sets of rows. Thus, there is no concept of sequence of entry unless you have columns which specifically capture this information. If that were the case, then we'd need to know how to determine which rows should appear should the order_number be null.
I was assuming that there is a setting that determines weather ALL the rows, ordered by their insertions into the database, will be returned when selecting ALL from the table. I was assuming this as this is how the database was functioning on the previous server. I gather that this is not the case and I will need to use the record number related to the order number to select all as a workaround.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.