SQL Min and Max

The SQL Min and Max functions are used to return the smallest and largest values from a specific column, respectively. These functions are useful when you need to find the extreme values in you dataset.

SQL Min and Max Syntax

SELECT MIN(column_name), MAX(column_name)
FROM table_name
WHERE condition;




SQL Min and Max Example

SQL Min and Max Finding the Oldest and Yougest Patients Example

This query reteieves the earliest (oldest patient) and the last (youngest patient) birthdates from the Patients table using the Min and Max functions.

SELECT MIN(dob) AS earliest_birthdate, MAX(dob) AS latest_birthdate
FROM Patients;



SQL Min and Max Finding the Lowest and Highest Dosages Example

This query finds the minimum and maximum dosage prescribed for ‘Ibuprofen’ from the Prescriptions table. The Min function returns the lowest doage, and the Max function returns the highest dosage.

SELECT MIN(dosage) AS lowest_dosage, MAX(dosage) AS highest_dosage
FROM Prescriptions
WHERE medication_name = 'Ibuprofen';




SQL Min and Max Visual Diagram




SQL Min and Max Labs

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top