MySQL Forums
Forum List  »  General

How to keep order of values inside IN() operator
Posted by: Lukas Pilny
Date: March 25, 2011 08:53PM

Hi,
I have maybe more theoretical question. Rather than explaining here goes the query:
SELECT * FROM t WHERE id IN(7,4,9,5,1);
The actual result is that the rows are fetched in ascending order by id - 1,4,5,7,9.
What I would like is to make possible to keep order in which are the id values inside IN() - 7,4,9,5,1. Is that possible somehow? Or do I have to rewrite completely the query to achieve that?
I cannot use ORDER BY on table t, because it doesn't contain the fields I need. The list of ids comes from other query, with lot of joins and many tables involved and is not important right now. My wish would be just to re-use the order in one single query.
Thanks a lot for any advice,
Luk

Options: ReplyQuote


Subject
Written By
Posted
How to keep order of values inside IN() operator
March 25, 2011 08:53PM


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.