Vidyalelo
MySQL · Q212

MySQL

Programming · MySQL · question 212

Q212

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
Answer
D.
None of the mentioned

Answer: Option C

Solution

Answer: Option C
Solution:
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.