0
0
MySQLquery~20 mins

GREATEST and LEAST in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
GREATEST and LEAST Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
1: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;
A3
B5
CNULL
D0
Attempts:
2 left
💡 Hint
Remember how GREATEST handles NULL values in MySQL.
query_result
intermediate
1: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;
A-10
B0
C3
D5
Attempts:
2 left
💡 Hint
LEAST returns the smallest value among the arguments.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in GREATEST usage
Which option contains a syntax error when using the GREATEST function in MySQL?
ASELECT GREATEST(1, 2, 3) AS max_value;
BSELECT GREATEST(4, 5, ) AS max_value;
CSELECT GREATEST(2, 3, NULL) AS max_value;
DSELECT GREATEST(5, '10', 7) AS max_value;
Attempts:
2 left
💡 Hint
Look for misplaced commas or missing arguments.
optimization
advanced
2: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?
ASELECT LEAST(math, science) + LEAST(english, 0) AS lowest_score FROM scores;
BSELECT CASE WHEN math < science AND math < english THEN math WHEN science < english THEN science ELSE english END AS lowest_score FROM scores;
CSELECT MIN(math, science, english) AS lowest_score FROM scores;
DSELECT LEAST(math, science, english) AS lowest_score FROM scores;
Attempts:
2 left
💡 Hint
Consider built-in functions that compare multiple values in one call.
🧠 Conceptual
expert
2:30remaining
Behavior of GREATEST and LEAST with different data types
What is the result of this query?

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;
Agreatest_val = 10, least_val = 5
Bgreatest_val = 10, least_val = 5 (both as strings)
Cgreatest_val = 10, least_val = 7
Dgreatest_val = '10', least_val = '7'
Attempts:
2 left
💡 Hint
MySQL converts strings to numbers when comparing numeric strings and numbers.