MySQL Forums
Forum List  »  General

Re: ORDER BY using specific order from IN
Posted by: Brian Moon
Date: May 16, 2006 08:40PM

Björn Steinbrink wrote:
> You can use FIND_IN_SET to do that:
> SELECT * FROM tablename WHERE id IN (1,10,8,5)
> ORDER BY FIND_IN_SET(id, '1,10,8,5')

Björn, nice trick.

when I run that, the rows come out in the opposite order of my set:

mysql> select article_id from article where article_id in (202, 1000, 500, 200) order by find_in_set(article_id, '202, 1000, 500, 200');
+------------+
| article_id |
+------------+
| 200 |
| 500 |
| 1000 |
| 202 |
+------------+
4 rows in set (0.00 sec)

Do you know if that is normal?

Brian Moon
Phorum Dev Team
----------------------------------------------------------
MySQL.com uses Phorum. Why don't you?
http://www.phorum.org/
----------------------------------------------------------

Options: ReplyQuote


Subject
Written By
Posted
Re: ORDER BY using specific order from IN
May 16, 2006 08:40PM


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.