0
0
SQLquery~20 mins

MIN and MAX functions in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
MIN and MAX Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Find the minimum salary from employees
Given the table Employees with columns id, name, and salary, what is the result of this query?
SELECT MIN(salary) FROM Employees;
SQL
SELECT MIN(salary) FROM Employees;
AReturns the smallest salary value from the Employees table
BReturns the largest salary value from the Employees table
CReturns the average salary value from the Employees table
DReturns the total number of employees
Attempts:
2 left
💡 Hint
MIN function finds the smallest value in a column.
query_result
intermediate
2:00remaining
Find the maximum order amount
Given the table Orders with columns order_id, customer_id, and amount, what does this query return?
SELECT MAX(amount) FROM Orders;
SQL
SELECT MAX(amount) FROM Orders;
AReturns the largest order amount
BReturns the smallest order amount
CReturns the total sum of all order amounts
DReturns the number of orders
Attempts:
2 left
💡 Hint
MAX function finds the largest value in a column.
🧠 Conceptual
advanced
2:00remaining
Understanding MIN and MAX with NULL values
Consider a table Scores with a column score that contains some NULL values. What will the query SELECT MIN(score) FROM Scores; return?
ANULL because there are NULL values in the column
BAn error because MIN cannot handle NULL values
CThe smallest value including NULLs
DThe smallest non-NULL score value
Attempts:
2 left
💡 Hint
Aggregate functions ignore NULL values by default.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in MIN usage
Which of the following SQL queries will cause a syntax error?
ASELECT MAX(amount) FROM Orders;
BSELECT MIN(salary) FROM Employees;
CSELECT MIN salary FROM Employees;
DSELECT MIN(age) FROM Persons;
Attempts:
2 left
💡 Hint
Aggregate functions require parentheses around the column name.
optimization
expert
3:00remaining
Optimizing MIN and MAX queries on large tables
You have a very large table Sales with millions of rows and a column sale_date. You want to find the earliest and latest sale dates efficiently. Which approach is best?
AUse SELECT MIN(sale_date), MAX(sale_date) FROM Sales; without any indexes
BCreate an index on sale_date and then run SELECT MIN(sale_date), MAX(sale_date) FROM Sales;
CRun two separate queries: SELECT MIN(sale_date) FROM Sales; and SELECT MAX(sale_date) FROM Sales; without indexes
DUse SELECT sale_date FROM Sales ORDER BY sale_date LIMIT 1; and SELECT sale_date FROM Sales ORDER BY sale_date DESC LIMIT 1;
Attempts:
2 left
💡 Hint
Indexes help speed up queries that search for minimum or maximum values.