IS NULL operator is used to comparing the NULL value. It is applicable in CRUD operation like create a query, read query, update query, and delete query.
For SELECT Statement
Syntax:-
SELECT column_name(s)
FROM table_name
WHERE column_name IS NULL
Example:- Suppose we have employees table which has 7 records
+----+------------+-----------+----------------+-----------+
| id | first_name | last_name | email | country |
+----+------------+-----------+----------------+-----------+
| 1 | John | Tailor | john@abc.com | USA |
| 2 | Rom | Tailor | rom@abc.com | USA |
| 3 | Andrew | Symonds | andrew@abc.com | Australia |
| 4 | Miacle | Tailor | miacle@abc.com | Australia |
| 5 | Sachin | Tendulkar | sachin@abc.com | India |
| 6 | Virat | Kohli | virat@abc.com | India |
| 7 | rohit | NULL | rohit@abc.com | India |
Find the employees details that have last_name value is NULL
Query:-
SELECT * FROM employees WHERE last_name IS NULL;
Output:-
+----+------------+-----------+---------------+---------+
| id | first_name | last_name | email | country |
+----+------------+-----------+---------------+---------+
| 7 | rohit | NULL | rohit@abc.com | India |
+----+------------+-----------+---------------+---------+
1 row in set (0.00 sec)
SQL IS NULL Operator – Interview Questions
Q 1: What is IS NULL used for?
Ans: It checks for NULL values.
Q 2: Can = be used for NULL comparison?
Ans: No.
Q 3: Is NULL equal to zero?
Ans: No.
Q 4: Can IS NULL be indexed?
Ans: Yes, in many databases.
Q 5: Can IS NULL be used in WHERE?
Ans: Yes.
SQL IS NULL Operator – Objective Questions (MCQs)
Q1. Which operator checks for NULL values?
Q2. Why can’t we use = NULL?
Q3. IS NULL returns rows where column value is:
Q4. IS NULL is used with which clause?
Q5. Which query is correct?