Skip site navigation (1) Skip section navigation (2)

Re: Sorting distinct dates by year and month respectively

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Matt Arnilo S(dot) Baluyos (Mailing Lists)" <matt(dot)baluyos(dot)lists(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Sorting distinct dates by year and month respectively
Date: 2006-06-07 14:56:20
Message-ID: 29995.1149692180@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-novice
"Matt Arnilo S. Baluyos (Mailing Lists)" <matt(dot)baluyos(dot)lists(at)gmail(dot)com> writes:
> ... ORDER BY date_part('year', article_pubdate),
> date_part('month', article_pubdate) DESC;

The above means

	... ORDER BY date_part('year', article_pubdate) ASC,
	date_part('month', article_pubdate) DESC;

You want

	... ORDER BY date_part('year', article_pubdate) DESC,
	date_part('month', article_pubdate) DESC;

As noted by the other respondent, sorting on one date_trunc column is
probably the better way to do it, but I thought I'd point out the DESC
issue anyway.  A lot of people get that wrong.

			regards, tom lane

In response to

pgsql-novice by date

Next:From: Richard Broersma JrDate: 2006-06-07 15:01:38
Subject: Re: Sorting distinct dates by year and month respectively
Previous:From: GregDate: 2006-06-07 13:35:35
Subject: Can PostGreSQL slow down a Windows PC much?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group