Jump to content

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
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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.