The ISNULL() function in MySQL is used to check whether an expression is NULL. It returns a boolean value: 1 if the expression is NULL, and 0 if it is not.
Syntax:
ISNULL(expression)
expression: The value or column that you want to check forNULL.
Example 1: Check if a column value is NULL
SELECT ISNULL(column_name) AS is_null
FROM table_name;
This query checks if the column_name contains NULL values and returns 1 for rows where the value is NULL and 0 for rows where it is not.
Example 2: Using ISNULL() in a WHERE clause
SELECT *
FROM employees
WHERE ISNULL(email);
This will return all rows where the email column is NULL.
Example 3: Using ISNULL() with a specific value
SELECT ISNULL(NULL) AS result;
This will return 1 because the value is NULL.
In MySQL, the ISNULL() function is sometimes confused with the IFNULL() function. The key difference is:
ISNULL()checks whether the value isNULL(returns1or0).IFNULL()is used to replace aNULLvalue with a specified value.
No comments:
Post a Comment