How to select the 10 largest numbers from a database column using SQL?

I have a database table that contains a column that records page hits for each record.

I want to select the 5 most popular pages from the database, but I can not find a suitable method for this, using only SQL. In particular, I am looking for one that does not include selecting each record and scanning through it using PHP.

What is the best way to do this through SQL (if any)?

Thank.

+3
source share
3 answers

Try this approach:

SELECT column1, column2, hit_pages,...
FROM YourTable
ORDER BY hit_pages DESC
LIMIT 5
+4
source

In MySQL> SELECT * FROM table ORDER BY hits DESC limit 5;

In Oralce> SELECT * FROM table ORDER BY hits DESC where rownum <5;

+3
source

10 ( ) (_) desc;

price
263.5 
123.79 
97 
81 
62.5 
55 
53 
49.3 
46 
45.6 
0

Source: https://habr.com/ru/post/1789492/


All Articles