sql - returning id in order from query -
say have following query
select * foo p_key in (5,7,2,6);
when enter query, p_key values return rows in order of 2,5,6,7. how can make returns rows in order entered in in clause
this
p_key 5 7 2 6
not this
p_key 2 5 6 7
you can't directly order order of items in in
clause. you'll have create temporary table or in-line sub-query add order values:
select foo.* foo inner join ( select 5 [key], 1 [order] union select 7 [key], 2 [order] union select 2 [key], 3 [order] union select 6 [key], 4 [order] ) j on p_key = j.key order j.[order]
Comments
Post a Comment