Examveda

What will be the output of the following MySQL command?
SELECT *
FROM person
WHERE emp_id = NULL;

A. Only those columns whose emp_id is NULL

B. Only those columns whose emp_id is not NULL

C. No output

D. None of the mentioned

Answer: Option C

Solution (By Examveda Team)

This question is about how MySQL handles NULL values in a WHERE clause.

The code you see:
SELECT *
FROM person
WHERE emp_id = NULL;


Is trying to find rows in the table 'person' where the 'emp_id' column is equal to NULL.

However, in SQL, comparing a value to NULL using '=' will always result in false.

This is because NULL represents an unknown or missing value.

So, the correct answer is:
Option C: No output

The query won't return any rows because it's looking for rows where 'emp_id' is exactly equal to NULL, which will never be true.

To find rows where 'emp_id' is NULL, you need to use the operator 'IS NULL'.

For example:
SELECT *
FROM person
WHERE emp_id IS NULL;


This code will correctly find rows where the 'emp_id' column is NULL.

This Question Belongs to MySQL >> MySQL Miscellaneous

Join The Discussion

Related Questions on MySQL Miscellaneous