Link to home
Start Free TrialLog in
Avatar of pmsguy
pmsguy

asked on

mysql ORDER BY based on IN clause

I want to ORDER my sql query based on the IN clause

select * from acct where acct_num in (200,100,150) order by (200,100,150)

My result is ordered by
100,150,200
I assume because acct_num is an index.

I want my resulting order to be
200,100,150
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pmsguy
pmsguy

ASKER

Is there an easier way to do this query?
The IN list will be dynamic.

not that I know of.
but if the "IN" list will be dynamic, so can be your order by?
Try this:
SELECT * FROM acct WHERE acct_num IN (200,100,150) ORDER BY FIELD(acct_num,200,100,150);

Open in new window

actually, that is a good one!