0 votes
1 view
in SQL by (20.3k points)

I have simple question:

I have a postgresql database: Scores(score integer).

How would I get the highest 10 scores the fastest?

UPDATE:

I will be doing this query multiple times and am aiming for the fastest solution.

1 Answer

0 votes
by (40.4k points)

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

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...