Description

The SQL keyword IS NULL is used to test for NULL values (or empty values).

  • It returns TRUE if the value is NULL or empty.
  • A NULL value is different from a zero value or a field containing spaces.
  • The NULL values cannot be validated with the comparison operators, like =< , ><>, etc.,
  • Always use IS NULL to validate a NULL value.

There is another operator IS NOT NULL, which works exactly opposite IS NULL operator.

SELECT With IS NULL

The below SQL fetches all the customers having a NULL value in the "city" column.

Run this on IDE

SELECT *
FROM customers
WHERE city IS NULL;

UPDATE With IS NULL

The below SQL updates the city column against all the customers having a NULL value in the "city" column.

UPDATE customers
SET city = 'DUMMY CITY'
WHERE city IS NULL;

DELETE With IS NULL

The below SQL deletes all the customers having a NULL value in the "city" column.

DELETE FROM customers
WHERE city IS NULL;

Related Links