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.
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
The command will locate the minimum value of the mark field and return. We can define
some header like this also.
SELECT MIN( mark ) FROM `student`
SELECT MIN(mark) as min_mark FROM `student`
Minimum mark in each class
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
SELECT class, min( mark ) as min_mark FROM `student` GROUP BY class
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.
Getting all the details of the record having minimum ( min ) data
Among the students who got the minimum mark? This is done by using union query. Like this .
Output is here
SELECT * FROM `student` WHERE mark=(select min(mark) from student)