mysql - SQL Sort Order by The Order Specified In the Query -


Say I have a question "Select from clause * where id (0,2,5,1,3) ) "And I really want the rows to be returned in the same order, where they are specified where the order of the segment ID will change from query to query and there will be no pattern for the order.

I know that it is possible to make changes in it. But I believe that such solutions will not work in my situation. I am also unable to change the order of the result object in my application code.

I know that different database engines sort differently, bat blah blah in some circumstances there is no guarantee. I just do not want it, is it possible?

I am using mysql or sql server if it helps :)

On MySQL, you can use it:

  ORDER BY FIND_IN_SET (ID, '0, 2,5,1,3')  
< P> To use the most portable medium CASE expression must be used:

  Case ID by order when 0 then 1 pm 2 then 2 when 5 then 3 when 1 was 4 when 3 to 5 END  

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -