Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL query for finding the first, second and third highest numbers

What is an example query to retrieve the first, second and third largest number from a database table using SQL Server?

like image 863
Sudhakar K Avatar asked Dec 10 '22 19:12

Sudhakar K


1 Answers

You can sort by your value descendingly and take the top 3.

SELECT TOP 3 YourVal FROM YourTable ORDER BY YourVal DESC
like image 96
pjp Avatar answered May 14 '23 04:05

pjp