It won't be fast, but

  SELECT id, title, description
  FROM table1
  WHERE id IN (4,1,3,6,8,2)
  ORDER BY FIND_IN_SET(id, '4,1,3,6,8,2');

See the manual for more <http://dev.mysql.com/doc/mysql/en/String_functions.html>.

Michael

Andrew Dixon - MSO.net wrote:

Hi Everyone.

I'm not sure if this is possible of not, but I want to sort a query by a
comma list. Here is what I'm doing:

SELECT id, title, description
FROM table1
WHERE   id IN (4,1,3,6,8,2)

This returns the results ok but they are not in any particular order. I want
the result in the order the ID's appear in the comma list in the IN
statement. Is there a ORDER BY statement I can add to do this?

So what I want to do is:

SELECT id, title, description
FROM table1
WHERE   id IN (4,1,3,6,8,2)
ORDER BY id in this order (4,1,3,6,8,2)

Thanks

Andrew.



-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to