How to get the top 10 values in postgresql?
I have a simple question:
I have a postgresql database: Scores(score integer).
How would I get the highest postgresql top10 scores the fastest?
UPDATE:
I will be doing this query multiple times and am aiming for the fastest solution.
To get the highest postgresql top10 scores you can use the limit, and try the code given below:
Query:
select *
from scores
order by score desc
limit 10
Note: If performance is not in the priority then you can look for an index on the score.
In version 8.4 and above, you can use the standard (SQL:2008) and fetch first like this:
Query:
select *
from scores
order by score desc
fetch first 10 rows only