View Single Post

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

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