I want to select columns from a table where the values of columns are NULL.
For example:
SELECT * FROM table1 WHERE column1 IS NULL;
the above query returns rows where column1 doesn't have any value.
But I want to return multiple columns(where column1,column2,....)
I want to use this in MYSQL
To search for column values that are NULL , you cannot use an expr = NULL test. The following statement returns no rows, because expr = NULL is never true for any expression: mysql> SELECT * FROM my_table WHERE phone = NULL; To look for NULL values, you must use the IS NULL test.
SELECT *
FROM table1
WHERE coalesce(column1, column2, column3) IS NULL;
You will have to enumerate all required columns. (I should confess this is a hack and should not be used in production code)
UPD
IF you want to check if at least a single column is null you should use OR:
SELECT *
FROM table1
WHERE column1 IS NULL or column2 IS NULL;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With