Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> SQL to sort based on a field condition
Hi,
I have the a table and records that I would like to
sort on based on the following conditions:
create table temptable (f1 varchar2(20), f2 varchar2(20), f3 varchar2(1));
f3 can only have values ('N','Y') and there can only be one 'Y' for each distinct f1
Table records
f1 f2 f3
ZOO BANANA N ZOO APPLE N ZOO ORANGE Y CASE OWL N CASE TIGER Y CASE MONKEY N Output after sorting f1 f2 f3
-------------------
CASE TIGER Y ->rec listed first because f3='Y' CASE MONKEY N CASE OWL N ZOO ORANGE Y ->rec listed first because f3='Y' ZOO APPLE N ZOO BANANA N
How should I write my SQL to achieve that?
TIA susan
-- Archives are at http://www.freelists.org/archives/oracle-l/ FAQ is at http://www.freelists.org/help/fom-serve/cache/1.htmlReceived on Fri Jun 25 2004 - 08:23:10 CDT
-----------------------------------------------------------------
![]() |
![]() |