Reputation: 237
I have a table like this:
Username Rating
1 xxxxxxxx -1
2 xxxxxxxx 2
3 xxxxxxxx 5
4 xxxxxxxx -2
5 xxxxxxxx 4
(Imagine if the table was bigger and had more than 20 rows). I want to write a MySQL statement in PHP that will return two lists: a list of the top ten highest values ordered by largest first, and a list of the top ten lowest values, ordered lowest first. How would I go about this?
Upvotes: 1
Views: 3278
Reputation: 74028
You order the result and use limit 10
select *
from mytable
order by rating
limit 10
or the top highest values
select *
from mytable
order by rating desc
limit 10
Upvotes: 2
Reputation: 10292
Ten highest:
SELECT Username, Rating FROM <Table> ORDER BY Rating DESC LIMIT 10;
Ten lowest:
SELECT Username, Rating FROM <Table> ORDER BY Rating ASC LIMIT 10;
Upvotes: 7