Challenge - 5 Problems
GREATEST and LEAST Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate1:30remaining
Output of GREATEST with NULL values
What is the output of the following MySQL query?
SELECT GREATEST(5, NULL, 3) AS result;MySQL
SELECT GREATEST(5, NULL, 3) AS result;
Attempts:
2 left
💡 Hint
Remember how GREATEST handles NULL values in MySQL.
✗ Incorrect
In MySQL, if any argument to GREATEST is NULL, the result is NULL.
❓ query_result
intermediate1:30remaining
LEAST function with negative and positive numbers
What is the output of this query?
SELECT LEAST(-10, 0, 5, 3) AS result;MySQL
SELECT LEAST(-10, 0, 5, 3) AS result;
Attempts:
2 left
💡 Hint
LEAST returns the smallest value among the arguments.
✗ Incorrect
Among -10, 0, 5, and 3, the smallest number is -10.
📝 Syntax
advanced2:00remaining
Identify the syntax error in GREATEST usage
Which option contains a syntax error when using the GREATEST function in MySQL?
Attempts:
2 left
💡 Hint
Look for misplaced commas or missing arguments.
✗ Incorrect
Option B has a trailing comma with no argument after it, causing a syntax error.
❓ optimization
advanced2:00remaining
Optimizing LEAST with columns and constants
Given a table
scores with columns math, science, and english, which query efficiently returns the lowest score for each student?Attempts:
2 left
💡 Hint
Consider built-in functions that compare multiple values in one call.
✗ Incorrect
LEAST directly compares all three columns and returns the smallest value efficiently.
🧠 Conceptual
expert2:30remaining
Behavior of GREATEST and LEAST with different data types
What is the result of this query?
Assume MySQL default type conversion rules.
SELECT GREATEST('10', 5, '7') AS greatest_val, LEAST('10', 5, '7') AS least_val;Assume MySQL default type conversion rules.
MySQL
SELECT GREATEST('10', 5, '7') AS greatest_val, LEAST('10', 5, '7') AS least_val;
Attempts:
2 left
💡 Hint
MySQL converts strings to numbers when comparing numeric strings and numbers.
✗ Incorrect
MySQL converts string numbers to numeric values for comparison. So GREATEST compares 10, 5, and 7 numerically, returning 10; LEAST returns 5.