Suppose a Student table has two columns, Name and Marks. 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.
Software Developer
Hi, my self Ravi Vishwakarma. I have completed my studies at SPICBB Varanasi. now I completed MCA with 76% form Veer Bahadur Singh Purvanchal University Jaunpur. SWE @ MindStick | Software Engineer | Web Developer | .Net Developer | Web Developer | Backend Engineer | .NET Core Developer
We can get name and marks of top 3 students as follows:
SELECT TOP 3 * FROM table_name ORDER BY column_name;
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
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.
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;