3

i have this kind of table and find the maximum mark

STUDENT

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

the out suppose to be like this

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

but i get this kind of output

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

i write this in sql

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

how can i correct the sql?

2 Answers 2

3

In SQL Server you can use

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

Though you could also use the logically equivalent standard SQL

SELECT *
FROM   student
WHERE  mark = (SELECT MAX(mark)
               FROM   student) 
Sign up to request clarification or add additional context in comments.

Comments

0

You can use this simple query to get same result:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.