In this part of query:
. . . WHERE col <> 10
It matches everything except 10 and NULL. While I want to match everything except only 10. So how can I exclude NULL of that?
In this part of query:
. . . WHERE col <> 10
It matches everything except 10 and NULL. While I want to match everything except only 10. So how can I exclude NULL of that?
This you can use for MySQL,
...WHERE IFNULL(col,0) <> 10
If the value of col is NULL then IFNULL(col,0) will convert the value to '0' and perform the comparison. So you will get all the records except only 10.
The problem is that the condition col != 10 (in MySQL) means "row where col has a value that is not 10". NULL is not a value so NULL rows aren't matched. If they were, you could have problems with NULLs cascading into other parts of your logic messing things up, since they don't use the same equality logic as values.
As far as I understand, doing it in two conditions (col IS NULL OR col != 10) is the proper way since by MySQL logic you're asking for two separate things. "rows where col has a value that is not 10, or rows where col has no value".