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 = '';
More SQL Articles
- How to Format a Number with Two Decimal Places in SQLite
- How to Order By Multiple Columns in SQL
- How to Count the Number of Rows with the Same Value
- How to Order a SQL String Column By Its Numeric Value
- How to Combine Columns Values Into a New Column in MySQL
- How to Drop Multiple Columns with ALTER TABLE in SQL
- What Stripe Data Do I Store in My Database?
- How To Query JSON Object with Unknown Keys in PostgreSQL
- How To Convert an Escaped JSON String in PostgreSQL to a JSON Object