What is IS NULL?
In SQL, IS NULL is used to check whether a column has a NULL value. A NULL represents missing or unknown data, not zero or an empty string.
2. Syntax
SELECT column1, column2
FROM table_name
WHERE column_name IS NULL;
column_name– The column you want to check for NULL values.table_name– The table containing the column.
3. Example
Suppose you have a table called Employees:
| EmployeeID | Name | Department |
|---|---|---|
| 1 | Alice | HR |
| 2 | Bob | NULL |
| 3 | Charlie | IT |
| 4 | David | NULL |
To find all employees without a department:
SELECT Name
FROM Employees
WHERE Department IS NULL;
Result:
| Name |
|---|
| Bob |
| David |
4. Using IS NOT NULL
To find rows where a column does have a value, use IS NOT NULL:
SELECT Name
FROM Employees
WHERE Department IS NOT NULL;
Result:
| Name |
|---|
| Alice |
| Charlie |
5. Key Points
IS NULLis used for filtering missing data.NULLis not the same as zero or empty string.- Always use
IS NULLorIS NOT NULL– do not use=or!=with NULL.