MySQL Forums
Forum List  »  General

Re: Finding a record's position when sorted
Posted by: toasty
Date: November 14, 2006 06:01PM

That works in simple cases, but not if the ORDER BY is complex, like:

SELECT * FROM tbl ORDER BY popularity, purchases;


I know I could do something like "WHERE ((popularity*100000)+purchases)>@var" but that's kinda messy. It also wouldn't work if one of the ORDER BY terms was ASC and the other DESC.


I don't remember which database system allowed this, but I remember doing something like:

SELECT * FROM tbl HAVING internal_row=500 ORDER BY popularity;

to use an internal/hidden row ID number that's added to each row after ORDER BY has finished its sort.

Is there anything similar in MySQL?

Options: ReplyQuote


Subject
Written By
Posted
Re: Finding a record's position when sorted
November 14, 2006 06:01PM


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.