Back

Explore Courses Blog Tutorials Interview Questions
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

Related questions

0 votes
0 answers
0 votes
1 answer
asked Dec 17, 2020 in SQL by Appu (6.1k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...