Jump to content

Archived

This topic is now archived and is closed to further replies.

Toni_montana

How to get last results out of my DB in order

Recommended Posts

Hey there,

This is my case. I have an mysql db in which names are stored. Some of them have a rating, some don't. Now i want to make a top 10 based on this rating. But i also want to show the 10 last ones. (i exclude the ones without a rating from the top10).

Now this is where i'm stuck because i also want to have the 10 last ones in a descending order. (So ORDER BY rating DESC LIMIT 10) won't do. I'll have to resort the result i get from this.

Anyone any ideas?

Rogier

Share this post


Link to post
Share on other sites
TOP 10...

SELECT * FROM table WHERE rating > '' ORDER BY rating DESC


Share this post


Link to post
Share on other sites
If your MySQL is 4.1 or greater you should be able to add another ORDER BY, basically a subquery:

[code](SELECT * FROM table ORDER BY rating DESC LIMIT 10) ORDER BY rating[/code]

I think that works but I can't remember trying it. If it doesn't, you can just make it a real subquery and put it in the FROM:

[code]SELECT f.* FROM (SELECT * FROM table ORDER BY rating DESC LIMIT 10) f ORDER BY f.rating[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.