W3. SQL Min and Max Flashcards
Q: What does the SQL MIN() function do?
A: Returns the smallest value in a selected column.
Q: What does the SQL MAX() function do?
A: Returns the largest value in a selected column.
Q: Write a query to find the lowest price in the “Price” column of the “Products” table.
SELECT MIN(Price) FROM Products;
Q: Write a query to find the highest price in the “Price” column of the “Products” table.
SELECT MAX(Price) FROM Products;
Q: What is the syntax for using MIN() or MAX() with a condition?
SELECT MIN(column_name) FROM table_name WHERE condition;
Q: How can you give a descriptive name to the result column of MIN() or MAX()?
A: Use the AS keyword to set an alias, e.g., SELECT MIN(Price) AS SmallestPrice.
Q: Write a query to find the smallest price in the “Products” table and label it as “SmallestPrice.”
SELECT MIN(Price) AS SmallestPrice FROM Products;
Q: How do you use MIN() with GROUP BY to return the smallest price for each category?
SELECT MIN(Price) AS SmallestPrice, CategoryID FROM Products GROUP BY CategoryID;