Handling NULL values in SQL

If a column’s field has NULL value then it means, it is blank. This field has no value.

When a column’s value is NULL then it can’t be determined by an eqal to (=) operator.

The way of identifying NULL values is, you need to use IS NULL or IS NOT NULL statement.

NOT NULL in SQL

SELECT * FROM result WHERE marks IS NULL;

This query will display all columns where price will be null.

IS NOT NULL in SQL

SELECT * FROM result WHERE marks IS NOT NULL;

This query will display all columns where price will not be null.

NULL values are filtered by a WHERE query.

Replace NULL values into specific values-

SQL provides a function coalesce() to replace null values with another value. By adding a placeholder like N/A, NONE, etc. you can make your report more meaningful to people.

SELECT students,coalesce(marks, 0) FROM result;

Leave a Comment