How to handle null values ​​in WHERE IN clause in mysql

I want to include possible values ​​to zero where in the condition in the mysql query. Here is my query: but it doesn't display any values. Please suggest that I include a null value in the WHERE IN state.

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

      

+3


source to share


3 answers


Try something like:

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

      



Here the expression will parse as COLUMN1 = 'YES' or COLUMN1 = 'NO' or field = 'NULL'. Entering NULL will give you COLUMN1 = null, which won't work.

+3


source


Try the following:



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

      

+2


source


Try the following:

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

+2


source







All Articles