Practice mode DBMS and SQL

Table Pay(id, salary, bonus) has one row (1, 5000, NULL). SELECT salary + bonus FROM Pay; What is returned?

Correct answer A. NULL

Explanation

In SQL, an arithmetic expression with a NULL operand yields NULL, because NULL means an unknown value and an unknown added to 5000 is still unknown. The result is not 5000; NULL is not treated as zero in expressions. Aggregates such as SUM skip NULLs, but row-level arithmetic does not. Write salary + COALESCE(bonus, 0) to treat a missing bonus as zero.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.