Desmond Hume
Desmond Hume

Reputation: 8607

Select rows based on non-equality, using just one condition

Suppose a table has a column num of type INT and the values in that column are allowed to be NULL. Now, provided that some rows has num cell set to some value and it's NULL for other rows, how do I select all the rows where num is not equal to a specific value, including the rows where num is NULL, using just one condition?

For example, if the num value I wanted to exclude from selection was 5, I would have to use a SELECT query with two conditions:

SELECT * FROM `table` WHERE `num` != 5 OR `num` IS NULL;

But how to make this simple retrieval using just one condition?

Upvotes: 0

Views: 127

Answers (1)

Pradeeshnarayan
Pradeeshnarayan

Reputation: 1235

hope this will help you.

SELECT * FROM `table` WHERE ifnull(`num`,0) != 5;

Upvotes: 2

Related Questions