mysqlnullwhere-in

How to handled the null values in WHERE IN condition in mysql


I want to include the possible values as null in where in condition in mysql query. Here is my query: But it is not displaying any values. Please suggest me how to include the null value in WHERE IN condition.

 SELECT * FROM TABLE1 WHERE COLUMN1 IN ('YES','NO',NULL);

Solution

  • Try something like :

    SELECT *
    FROM TABLE1 
    WHERE (COLUMN1 IN ('YES', 'NO') OR COLUMN1 IS NULL)
    

    Here in statement will be parsed like COLUMN1='YES' or COLUMN1='NO' or field='NULL'. Putting a NULL in there will get you COLUMN1=null which won't work.