Re: order by date desc but NULLs last

From: "Tomasz Myrta" <jasiek(at)klaster(dot)net>
To: "A(dot)M(dot)" <agentm(at)cmu(dot)edu>, pgsql-sql(at)postgresql(dot)org
Subject: Re: order by date desc but NULLs last
Date: 2003-02-09 23:12:11
Message-ID: 20030210071211.M27958@klaster.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> I have a simple query that sorts by descending date but the NULL
> dates show up first. Is there a way I can sort so they come last
> without sorting ascending?
>
> SELECT submittime,score,gradedtime FROM student_gradedmaterial WHERE
> gradedmaterialid=3 and studentid=102 order by gradedtime desc;
>
> submittime | score | gradedtime
> ---------------------+-------+----------------------------
> 2003-01-30 22:56:38 | |
> 2003-01-31 03:42:29 | 99 | 2003-02-06 14:21:43.043587
>
> but what I want is all the graded items first in gradedtime desc and
> NULL afterwards. I do need to keep the NULL score rows. (So I get
> the latest submitted grade for the assignment but also any ungraded
> submission information.)
>
> Thanks for any advice.
> ><><><><><><><><><
> AgentM
> agentm(at)cmu(dot)edu

order by gradetime is null asc, gradetime desc;

Regards,
Tomasz Myrta

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tomasz Myrta 2003-02-09 23:17:18 Re: How to delete duplicate record
Previous Message Ross J. Reedstrom 2003-02-09 23:12:04 Re: order by date desc but NULLs last