List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:March 12 2002 4:21am
Subject:Re: Order by list?
View as plain text  
At 20:00 -0800 3/11/02, George Marnellos wrote:
>Hi all,
>I'm executing the follow very simple type of query to select entries from a
>"select entryid, entryinfo from mytable where entryid in ('id7', 'id4',
>'id2', 'id5')"
>and, even though I don't specify any sorting order, MySQL sorts
>by the field "entryid" (which happens to be an index), i.e. it returns
>| entryid  | entryinfo |
>| id2	     |       ... |
>| id4      |       ... |
>| id5      |       ... |
>| id7      |       ... |
>I don't want this sorting order; I want the order to be that of the list. Is
>there a
>way to do this? It appears very simple but I cannot find how.

Use an ORDER BY clause that looks like this:

ORDER BY FIELD(entryid,'id7','id4','id2','id5')

>Thanks for any comments or help,

Order by list?George Marnellos12 Mar
  • Re: Order by list?Paul DuBois12 Mar
RE: Order by list?John Lodge12 Mar