Bird
0
0

Given the table Employees with columns id, bonus (nullable), what is the result of this query?

medium📝 query result Q13 of 15
SQL - CASE Expressions
Given the table Employees with columns id, bonus (nullable), what is the result of this query?
SELECT id, COALESCE(bonus, 100) AS bonus_amount FROM Employees WHERE id = 1;

Assuming the row with id=1 has bonus = NULL.
ANo rows returned
B[{"id": 1, "bonus_amount": 100}]
C[{ "id": 1, "bonus_amount": 0 }]
D[{ "id": 1, "bonus_amount": NULL }]
Step-by-Step Solution
Solution:
  1. Step 1: Understand COALESCE with NULL bonus

    Since bonus is NULL for id=1, COALESCE returns the second argument, 100.
  2. Step 2: Check query output

    The query selects id=1 and bonus_amount as 100, so the result is [{"id": 1, "bonus_amount": 100}].
  3. Final Answer:

    [{"id": 1, "bonus_amount": 100}] -> Option B
  4. Quick Check:

    COALESCE(NULL, 100) = 100 [OK]
Quick Trick: COALESCE returns first non-NULL, here 100 [OK]
Common Mistakes:
  • Assuming NULL is returned instead of 100
  • Confusing COALESCE with NULLIF
  • Expecting zero instead of 100

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes