Re: Orderby two different columns

From: "Oliver Elphick" <olly(at)lfix(dot)co(dot)uk>
To: "Mitch Vincent" <mitch(at)venux(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org, olly(at)linda(dot)lfix(dot)co(dot)uk
Subject: Re: Orderby two different columns
Date: 2000-06-23 16:07:20
Message-ID: 200006231607.e5NG7Ke23404@linda.lfix.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Mitch Vincent" wrote:
>I need to order search results by the two dates. Here is the problem..
>
>They want whichever date is the most recent to appear on top.. If I do
>'order by resubmitted desc,created desc' I get something like this :
>
>Applicant Re-submitted Created
>A 06/05/2000 12/31/1999
>B 06/05/2000 12/31/1999
>C 05/17/2000 02/09/2000
>D 05/17/2000 01/21/2000
>E 05/11/2000 01/27/2000
>F 05/11/2000 01/21/2000
>G 05/01/2000 12/31/1999
>H 04/28/2000 01/28/2000
>I 04/28/2000 01/12/2000
>J 05/23//2000
>
>
>Ok, see applicant J? I need him to be above C..

select * from table
order by case
when resubmitted > created then resubmitted
else created
end
desc;

--
Oliver Elphick Oliver(dot)Elphick(at)lfix(dot)co(dot)uk
Isle of Wight http://www.lfix.co.uk/oliver
PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47 6B 7E 39 CC 56 E4 C1 47
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"Train up a child in the way he should go, and when he
is old, he will not depart from it." Proverbs 22:6

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Andrew Snow 2000-06-23 16:17:05 RE: Need to improve performance
Previous Message Tom Lane 2000-06-23 15:59:03 Re: Orderby two different columns