View Single Post

   
  #7 (permalink)  
Old 02-28-2008, 09:30 AM
Yobbo
 
Posts: n/a
Default Re: Getting back set order from the IN param

Hi Bill

Many thanks for this.

Do you know if your method is more efficient than Dimitre's
FIELD(TOKENID,6,20,234,19,32,4,800,177) method??

Rgds Yobbo



"Bill Karwin" <bill@karwin.com> wrote in message
news:eimeo201jf8@enews3.newsguy.com...
Yobbo wrote:
> SELECT STRINGTEXT, TOKENID
> FROM WEBSTRINGS
> WHERE TOKENID IN (6,20,234,19,32,4,800,177)
>
> All I want is my resultset to come back in the order that I have defined
> in
> the IN clause


See the docs for FIND_IN_SET() here:
http://dev.mysql.com/doc/refman/5.0/...functions.html

For example:

SELECT STRINGTEXT, TOKENID
FROM WEBSTRINGS
WHERE TOKENID IN (6,20,234,19,32,4,800,177)
ORDER BY FIND_IN_SET(TOKENID, '6,20,234,19,32,4,800,177')

Note the quotes: IN() has variable arguments which are a
comma-separated list of integers, but FIND_IN_SET() has two arguments,
the latter of which is a quoted string.

Regards,
Bill K.


Reply With Quote