Given this sample table:
ID_no name grade
112 Micheal 81
113 Airi 90
114 Felix 76
115 Ana 87
how do i get the top 3 names based on their given grades…
You just have to use the
TOPclause in combination with your desired order:(assuming that a higher grade is better)
Note that you need
SELECT TOP 3 WITH TIES(as John has shown) to include all rows with the same number. So consider that there are 5 names with the same grade, my query would only return 3 whereasWITH TIESensures that all 5 are returned.