0
0
MySQLquery~5 mins

GREATEST and LEAST in MySQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A3
B5
C10
DNULL
What will LEAST(7, 2, 9) return?
A7
BNULL
C9
D2
What does GREATEST(4, NULL, 6) return in MySQL?
ANULL
B6
C4
DError
Which function would you use to find the smallest value among columns in MySQL?
ALEAST
BMAX
CGREATEST
DMIN
What will LEAST('apple', 'banana', 'cherry') return?
A'cherry'
B'apple'
C'banana'
DNULL
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.