Skip to content
Advertisement

MYSQL syntax not evaluating not equal to in presence of NULL

I am having trouble with a mysql query. I want to exclude values of 2. So I thought I would do following:

However, This is not giving the desired result of product1, product 2 It is giving an empty results table.

On the other hand if I use

Then it produces: product3. But I want to get those records where it is not equal to 2.

Something is not working with the <> '2'. Could it be that the NULL values are throwing it off? Can anyone suggest a fix.

Thanks in advance!

Advertisement

Answer

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

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement