Find max data on sql server

I have a table like this and find the max elevation

STUDENT

|id | name  | mark |
|1  | john  | 56   |
|2  | sara  | 81   |
|3  | mattew| 65   |

      

suppose it will be

|id | name  | mark |
|2  | sara  | 81   |

      

but i get this kind of output

|id | name  | mark |
|1  | john  | 81   |

      

I am writing this in sql

SELECT id,name,MAX(mark)
FROM student;
WHERE name IN
(SELECT name
FROM student);

      

how can i fix sql?

+3


source to share


2 answers


In SQL Server, you can use

SELECT TOP 1 WITH TIES *
FROM student
WHERE mark IS NOT NULL
ORDER BY mark DESC

      



While you can also use the logically equivalent standard SQL

SELECT *
FROM   student
WHERE  mark = (SELECT MAX(mark)
               FROM   student) 

      

+3


source


You can use this simple query to get the same result:



  SELECT TOP 1 WITH TIES ID,NAME,mark 
    FROM STUDENT
    ORDER BY MARK DESC

      

0


source







All Articles