Basics & SELECT Queries · SQL SQL

How does SQL handle NULL values when comparing them with standard comparison operators like equals (=) or not equals (<>) in a WHERE clause?

Practice question from Basics & SELECT Queries (SQL SQL), with the correct answer and a step-by-step solution.

medium · MCQ · Q-9AAE6F

How does SQL handle NULL values when comparing them with standard comparison operators like equals (=) or not equals (<>) in a WHERE clause?

  1. A.NULL is treated as equivalent to zero.
  2. B.NULL is treated as an empty string.
  3. C.Any comparison with NULL evaluates to UNKNOWN, resulting in no rows matched.Correct answer
  4. D.Standard comparison operators automatically evaluate NULL as true.

Solution

In SQL three-valued logic, NULL represents missing or unknown data. Any standard comparison with NULL yields UNKNOWN, so the WHERE clause filters out those rows. The IS NULL or IS NOT NULL operators must be used instead.

More from Basics & SELECT Queries

All of Basics & SELECT Queries

Practise more SQL

Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.

Start practising free

Free to start · No credit card needed