I am trying to find the n largest numbers in a particular column in SQL Server.
We can find the largest value in a column and the 2nd largest value easily.
But how do I find say, 5 largest values in a column ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In MySql you can use
[LIMIT {[offset,] row_count }]to do this like so:For SQL Server you can use the
TOP(n)to get the top n:For example:
Update: If you have another table
familieswith a foreign keyfamily_IDto products table, and you want to find all products with the top n family id’s. Then you can dot this:Update 2: The topmost product in each family:
Here is alive demo