How to get names and marks of the top three students.

Suppose a Student table has two columns, Name and Marks. How to get names and marks of the top three students.

Last updated:9/22/2021 2:33:36 AM

2 Answers

Ashutosh Kumar Verma
Ashutosh Kumar Verma

SQL SELECT Highest value:

 To find the highest value from given records of column in a table then the following SQL statement is used for it,

SELECT TOP N * FROM table_name ORDER BY column_name DESC;

And find the min value from that table then,

SELECT TOP N * FROM table_name ORDER BY column_name ;(or ASC ;)

Example:

Lets have a database table ‘Students’ that store the record of students.

    How to get names and marks of the top three students.

The following SQL statement is used to find the records of 3 students who get the highest marks.

select top 3 stuName, stuMarks from Students order by stuMarks desc;

      How to get names and marks of the top three students.

Shivani Kashyap
Shivani Kashyap

The names and marks of the top three students are obtained using a SELECT statement. The following SQL statement is used to determine the column in a table's given records with the highest value:

SELECT TOP N * FROM table_name ORDER BY column_name DESC;

You can write the query. 

SELECT TOP 3* FROM students ORDER BY marks DESC; 

if you want to learn more about databases, for example, Oracle Database you can join Oracle Online Course and solve these questions easily hope you like this 

Answer