Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Sorting in a select - help!
Hi,
to dynamically be able to choose which column to sort you could use a teqnique as described below, using decode to return the columns you want to sort on.
select ..
from ..
order by decode(&flag,1,column1,2,column2,3,column3,...)
If you want to reveres the sort yust use desc after each column you want to sort descending like this: order by column1 desc , column2 desc,....
Rgds
Steinar Heggelund
Nils (nils_at_bourbon.propertymall.com) wrote:
: I wish to make a select and have the data sorted, i.e.
: select * from DTABLE
: where
: (
: QTOWN = DTABLE.TOWN
: )
: order by size_000_s ;
: Questions: (to which, having consulted a couple of books,
: I cannot find a solution)
: (1) There are 3 different columns by which I could sort, i.e. size, date and so on - how can I do this - essentially I qould like to pass a parameter QSORT and then sort by size if it is 0, date if it is 1 and so on?
: (2) How can I reverse a sort - instead of the reault being sorted lowest to highest numeric value, I would like it sorted highest to lowest.
: Thanks,
: Nils
Received on Wed Mar 19 1997 - 00:00:00 CST