Bird
0
0

Given a table Products with columns price (nullable) and discount (nullable), what will this query return?

medium📝 query result Q4 of 15
SQL - CASE Expressions
Given a table Products with columns price (nullable) and discount (nullable), what will this query return?
SELECT COALESCE(discount, price, 0) AS final_price FROM Products;
AThe sum of discount and price or 0 if both are NULL
BAn error because COALESCE cannot have more than two arguments
COnly the discount value or 0 if discount is NULL
DThe first non-NULL value among discount, price, or 0 for each row
Step-by-Step Solution
Solution:
  1. Step 1: Understand COALESCE evaluation order

    COALESCE returns the first non-NULL value from left to right.
  2. Step 2: Apply to given columns

    It checks discount first, if NULL then price, if both NULL then 0.
  3. Final Answer:

    The first non-NULL value among discount, price, or 0 for each row -> Option D
  4. Quick Check:

    COALESCE returns first non-NULL value in order [OK]
Quick Trick: COALESCE checks values left to right, returns first non-NULL [OK]
Common Mistakes:
  • Thinking COALESCE sums values
  • Assuming COALESCE only works with two arguments
  • Expecting error due to multiple arguments

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes