Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SQL : Sort on Multiple Columns.

SandeepanMar 5 2015 — edited Mar 8 2015

Hi ,

I have a query as below ;

I need to fetch records  order by multiple columns.
e.g.

select * from my_tab order by col1 desc ,col2 ;

But ,  I need to sort based on a relation between col1 , col2

e.g. say  , one of the records to be fetched has col1 has value of 5 and col2 has a value of 6
another record to be fetched has col1 has value of 2 and col2 has a value of 1
Now , If I run the above query , first I will get the record( say , R1) that has col1,col2 values as 5,6 ;  the record(say ,R2) that has col1,col2 values as 2,1 will come next.
But , I want R2 to come first  , I want to first fetch those records which have col1>col2
Please advise how to model the query accordingly.
Thanks.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 5 2015
Added on Mar 5 2015
13 comments
534 views