Since we have twoĬlass in our table so the sql command has returned two class with highest mark inīy clause if we ask for the query to return any other field name other than You can see above that maximum mark of each class is displayed. SELECT class, max( mark ) as max_mark FROM Here we can use the Groupīy command to find out the maximum mark obtained by each class Now let us find out what is the maximum mark ( or highest ) in each class. Maximum mark in each class by using Group By SELECT * FROM `student` WHERE mark=(select max(mark) from student) id We can get matching output of id, name,class by using where clause by matching with maximum mark using subquery SELECT id,name,class,MAX(mark) as max_mark FROM `student`Īs you can see below the above query will display Maximum mark but not the matching id, name, class. This will display one record with all details of the highest mark To display all fields like name, class, id along with the highest mark we can use like this. SELECT MAX(mark) as max_mark FROM `student` The command collected the maximum value of the mark field and displayed.
0 Comments
Leave a Reply. |