'get max value of each column group by student ID
I have a table with columns like this
Std_id Class Section
14 8 2
14 8 1
14 9 1
15 8 3
15 8 2
15 8 1
Now I want student max class and max section by unique Student ID Like this
Std_id Class Section
14 9 1
15 8 3
I tried following queries with no success
SELECT std_id, class, section FROM `session` GROUP BY std_id ORDER BY std_id ASC,class DESC,section DESC
And
SELECT DISTINCT student_id, class_id, section_id FROM `student_session` ORDER BY student_id ASC,class_id DESC,section_id DESC
Solution 1:[1]
Try out this query
SELECT std_id, MAX(class),MAX(section) FROM student GROUP BY std_id
Solution 2:[2]
It should help:
SELECT Std_id, MAX(Class) as max_class, MAX(Section) as max_section
FROM student
GROUP BY Std_id
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Harshil Khamar |
| Solution 2 |
