SQL PHP HTML ASP JavaScript articles and free scripts to download
 
 

SQL MIN Command

Minimum value in a numeric field can be collected by applying  MIN sql command. We will try MIN sql command and how to use it in our tables. But the best way to use MIN command is to apply it in a numeric field. Here is our table with all the records. 

id name class mark
1 John Deo Four 75
2 Max Ruin Three 85
3 Arnold Three 55
4 Krish Star Four 60
5 John Mike Four 60
6 Alex John Four 55
 
You can check SQL MAX command to get maximum or highest value of a range of records.

We will apply the MIN command here like this to the field  mark

SELECT MIN( mark ) FROM `student`
MIN(mark)
55
The command will locate the minimum  value of the mark field and return. We can define some header  like this also.
SELECT MIN(mark) as min_mark FROM `student` 

min_mark
55

Now let us find out what is the minimum mark ( or lowest ) in each class. Here we can use the Group By command to find out the minimum mark obtained by each class
Related Tutorial
MySQL Max
MySQL Avg
MySQL Sum



SELECT class, min( mark ) as min_mark FROM `student` GROUP BY class

class min_mark
Four 55
Three 55

Here  minimum mark of each class is displayed. Since we have two class in our table so the sql command has returned two class with lowest mark in each of them. We have to use Group By clause if we ask for the query to return any other field name other than the min. Otherwise system will generate error.
Discuss this tutorial at forum

List of SQL Tutorials


Further readings
avg:Getting average of data in MySQL
sum:Sum of a range of data in MySQL
min:Getting the Minimum value of data in MySQL
max:Getting the Miximum value of data in MySQL
Getting second highest number from the student table
format: Formatting MySQL data in a query while managing records of a table
 
Scripts
PHP
JavaScript
HOME
SQL Tutorial List
SQL (Home)
SQL Commands
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.