Skip to content
Advertisement

Getting student name with highest total mark in SQL

I have table named ‘marks’ which stores marks of students.

     id name      social math   science
     2  Max Ruin    85   85      56 
     3  Arnold      75   40      170
     4  Krish       60   70      50
     5  John        60   90      80

I want to get the name of student who has highest total mark.

I tried query like this

 SELECT name, (social + math +science) AS total_mark FROM marks where total_mark = max(total_mark );

But this is not working. Can anyone please help ?

Advertisement

Answer

get the max() total first then use a subquery

    select * from marks where (social+math+science) =    
      (select max(social+math+science) from marks); 
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement