Jump to content


Photo

How to get last results out of my DB in order


  • Please log in to reply
3 replies to this topic

#1 Toni_montana

Toni_montana
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 07 March 2006 - 01:24 PM

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

#2 Toni_montana

Toni_montana
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 12 March 2006 - 05:40 PM

Guys,

NOBODY of you can solve this one?

Seems i'm only helping others these days...

#3 wisewood

wisewood
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 12 March 2006 - 06:23 PM

TOP 10...

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



wisewood: proven fact, I am both wise, and wooden.

#4 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 12 March 2006 - 07:30 PM

If your MySQL is 4.1 or greater you should be able to add another ORDER BY, basically a subquery:

(SELECT * FROM table ORDER BY rating DESC LIMIT 10) ORDER BY rating

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:

SELECT f.* FROM (SELECT * FROM table ORDER BY rating DESC LIMIT 10) f ORDER BY f.rating





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users