Recall & Review
beginner
What does the GREATEST function do in MySQL?
The GREATEST function returns the largest value from a list of values. It compares all values and gives back the highest one.
Click to reveal answer
beginner
What does the LEAST function do in MySQL?
The LEAST function returns the smallest value from a list of values. It compares all values and gives back the lowest one.
Click to reveal answer
intermediate
How does GREATEST handle NULL values in MySQL?
If any value in the list is NULL, GREATEST returns NULL. NULL means unknown, so the result is unknown.
Click to reveal answer
intermediate
How does LEAST handle NULL values in MySQL?
If any value in the list is NULL, LEAST returns NULL. NULL means unknown, so the result is unknown.
Click to reveal answer
beginner
Write a MySQL query using GREATEST to find the highest score among three columns: score1, score2, score3.
SELECT GREATEST(score1, score2, score3) AS highest_score FROM your_table;
Click to reveal answer
What will GREATEST(5, 10, 3) return?
✗ Incorrect
GREATEST returns the largest value, which is 10.
What will LEAST(7, 2, 9) return?
✗ Incorrect
LEAST returns the smallest value, which is 2.
What does GREATEST(4, NULL, 6) return in MySQL?
✗ Incorrect
If any value is NULL, GREATEST returns NULL.
Which function would you use to find the smallest value among columns in MySQL?
✗ Incorrect
LEAST returns the smallest value among the given values.
What will LEAST('apple', 'banana', 'cherry') return?
✗ Incorrect
LEAST compares strings alphabetically and returns 'apple' as it comes first.
Explain how GREATEST and LEAST functions work in MySQL and how they handle NULL values.
Think about comparing numbers or strings and what happens if one value is unknown.
You got /4 concepts.
Write a simple MySQL query using GREATEST to find the highest value among three columns in a table.
Use SELECT GREATEST(column1, column2, column3) AS alias FROM table;
You got /3 concepts.