MYSQL syntax not evaluating not equal to in presence of NULL

Sorry to open this

We can use this also

SELECT name 
from   products p
WHERE  COALESCE(backorder,1)  <> 2

use IS NULL or IS NOT NULL to compare NULL values because they are simply unknown.

SELECT name 
from   products p
WHERE  backorder IS NULL OR backorder <> 2
  • SQLFiddle Demo
  • SQLFiddle Demo (added some records)

  • Working with NULL Values


Use the <=> operator.

You can use:

SELECT `name` FROM `products` `p`
WHERE NOT `backorder` <=> '2'

or

SELECT `name` FROM `products` `p`
WHERE !(`backorder` <=> '2')

See this answer for more information about the <=> operator:

What is this operator <=> in MySQL?

Tags:

Mysql

Sql