MySQL Forums
Forum List  »  General

ORDER BY using specific order from IN
Posted by: Daniel Hofverberg
Date: May 16, 2006 03:46AM

Is there any way to SELECT a number of posts with an IN statement, and order them in that specific order?

I e, I have a query similar to the following:
SELECT *
FROM tablename
WHERE id IN(1,10,8,5)

And I want to order the results in the order listed in the IN statement (in the above example: id 1, followed by 10, 8 and 5). Obviously ORDER BY id won't work, as that will order them ascending instead of the order given.

Is there any way to sort the posts as the IN statement indicates?

I'm currently using MySQL version 5.1.16.




Edited 2 time(s). Last edit at 05/16/2006 03:54AM by Daniel Hofverberg.

Options: ReplyQuote


Subject
Written By
Posted
ORDER BY using specific order from IN
May 16, 2006 03:46AM


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.