Recall & Review
beginner
What does the IF function do in MySQL?
The IF function checks a condition and returns one value if the condition is true, and another value if it is false.
Click to reveal answer
beginner
Write the syntax of the IF function in MySQL.
IF(condition, value_if_true, value_if_false)
Click to reveal answer
intermediate
How does the IF function differ from the CASE statement in MySQL?
IF is used for simple two-way decisions (true/false), while CASE can handle multiple conditions and outcomes.
Click to reveal answer
beginner
Example: What will this query return? SELECT IF(5 > 3, 'Yes', 'No');
It will return 'Yes' because 5 is greater than 3, so the condition is true.
Click to reveal answer
intermediate
Can the IF function be nested inside another IF function in MySQL?
Yes, you can nest IF functions to check multiple conditions step-by-step.
Click to reveal answer
What will this MySQL query return? SELECT IF(10 = 10, 'Equal', 'Not Equal');
✗ Incorrect
The condition 10 = 10 is true, so IF returns 'Equal'.
Which part of IF(condition, value_if_true, value_if_false) is evaluated first?
✗ Incorrect
The condition is evaluated first to decide which value to return.
Can IF function return NULL as a value_if_true or value_if_false?
✗ Incorrect
IF can return NULL for either true or false results.
Which of these is a valid use of IF in MySQL?
✗ Incorrect
Option B uses correct IF syntax with condition and two values.
What happens if the condition in IF is NULL?
✗ Incorrect
If condition is NULL, it is treated as false, so IF returns value_if_false.
Explain how the IF function works in MySQL and give a simple example.
Think about a question with two possible answers.
You got /4 concepts.
Describe a situation where nesting IF functions would be useful in a database query.
Imagine checking age groups or multiple categories.
You got /3 concepts.