Limiting SQL Statement to top 5 amounts

sql

Solution

You'd have to sort by that column value, maybe in descending order, depending on what you mean by "top 5" ; and fetching only the 5 top lines.

Using MySQL, you'd have something like this, I'd say :

select *
from your_table
where ...
order by your_column desc
limit 5

Using MSSQL server, you don't have `limit`, but you could use `top` :

select top 5 *
from your_table
where ...
order by your_column desc

Problem

How do I write a simple SELECT statment which limits the report to only the top 5 of a column value?

Original source