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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
not that I know of.
but if the "IN" list will be dynamic, so can be your order by?
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);
actually, that is a good one!
ASKER
The IN list will be dynamic.