in reply to Re: Sorting and Grouping with two different fields
in thread Sorting and Grouping with two different fields

I can not use "OREDR BY state DESC" so that Virginia will come up. When I sort by state with " DESC state, id ASC" the order of states will be "Washington, Virginia,Indiana". But I need it sorted by id, but grouped with state.

--VC

Replies are listed 'Best First'.
Re^3: Sorting and Grouping with two different fields
by Tobin Cataldo (Monk) on Jul 12, 2007 at 13:48 UTC
    I would just add another field SMALLINT from 1-50 called sort_order and then you can apply your arbitrary sort order to each state...
    UPDATE table1 SET sort_order = 1 WHERE state = "Virginia"
    Then you can
    ORDER BY sort_order DESC, city DESC

      Your answer is too specific. If its dealing with only 50 states of US, Its OK to assign 1-50 called sort order. Here I am NOT allowed to alter the structure of the table as there are many other programs that depends on no of columns and other structure of the table. I am NOT allowed to add any temperory table. We wont mind the overhead caused by the sort algorith implemented. What I am looking for is a logic like Limbic~Region suggested.