How to Check if a Column is Null in MySQL
Suppose we want to write a SQL query that checks if a column is NULL
in MySQL.
We can write this condition using IS NULL
and IS NOT NULL
.
SELECT * FROM table_name
WHERE col_name IS NULL;
Empty strings are not considered null in MySQL, but if we want them to be included in our check, we can add that very easily.
SELECT * FROM table_name
WHERE col_name IS NULL OR col_name = '';