MySQL Forums
Forum List  »  General

Finding a record's position when sorted
Posted by: toasty
Date: November 14, 2006 03:39PM

Suppose I have a huge table, that could be sorted in dozens of possible ways, using ORDER BY. What's the recommended way of determining what a specific record's position would be if sorted in a specific way?

For example, each row has lots of different values that I might want to ORDER BY on. How do I say "What position would this row appear at, if I sorted by 'ORDER BY popularity'"?

I can say:

SELECT * FROM mytable ORDER BY popularity LIMIT 500,1

to find out what the 500th most popular record is. How do I do the inverse? I have a record (with a unique index associated to it), and want to know what position it would appear in if I sorted the whole table by "popularity". Or by any other number of complicated ORDER BYs.

Options: ReplyQuote


Subject
Written By
Posted
Finding a record's position when sorted
November 14, 2006 03:39PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.