Arne De Smedt
Arne De Smedt

Reputation: 755

Mysql column comparison 'different from 0' but not from NULL

If I select a column from a MYSQL column, I try to check if it's different from zero (0) by the following constraint:

WHERE my_column_name <> 0

It returns false if it's zero (0) but also if it's NULL. And that's not the purpose.

How do I have to solve this problem?

Upvotes: 1

Views: 46

Answers (1)

Wrikken
Wrikken

Reputation: 70540

NULL - safe comparison is done with <=>, you only need to add a NOT() as an alternative:

   WHERE NOT(my_column_name <=> 0)

Upvotes: 4

Related Questions