Recall & Review
beginner
What does the SQL function COALESCE do?
COALESCE returns the first non-NULL value from a list of expressions. If all values are NULL, it returns NULL.
Click to reveal answer
beginner
How does COALESCE help with NULL values in SQL queries?
It allows you to replace NULL values with a default or alternative value, making results easier to read and process.
Click to reveal answer
beginner
Example: What is the result of COALESCE(NULL, NULL, 'apple', 'banana')?
The result is 'apple' because it is the first non-NULL value in the list.
Click to reveal answer
beginner
Can COALESCE take more than two arguments?
Yes, COALESCE can take two or more arguments and returns the first non-NULL among them.
Click to reveal answer
intermediate
How is COALESCE different from ISNULL or NVL?
COALESCE is standard SQL and can take multiple arguments, while ISNULL (SQL Server) and NVL (Oracle) usually take two arguments and are vendor-specific.
Click to reveal answer
What will COALESCE(NULL, 'Hello', 'World') return?
✗ Incorrect
COALESCE returns the first non-NULL value, which is 'Hello'.
If all arguments in COALESCE are NULL, what is the result?
✗ Incorrect
COALESCE returns NULL if all arguments are NULL.
Which of these is a valid use of COALESCE?
✗ Incorrect
COALESCE requires at least two arguments; option D is valid.
COALESCE is most similar to which function?
✗ Incorrect
COALESCE and ISNULL both handle NULL values by returning a replacement.
What does COALESCE(NULL, NULL, NULL) return?
✗ Incorrect
All arguments are NULL, so COALESCE returns NULL.
Explain how COALESCE helps handle NULL values in SQL queries.
Think about what happens when you have missing data.
You got /3 concepts.
Write a simple SQL example using COALESCE to replace NULL with 'N/A'.
Use COALESCE with two arguments.
You got /3 concepts.