0

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
  • 2
    NULL is considered unknown value so it is not equal or unequal with anything.You want ...AND (orders <> 'Returned' OR orders IS NULL) Also VALUES is a reserved word Commented Jan 7, 2016 at 20:55

1 Answer 1

3

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.