Re: Sorting distinct dates by year and month respectively

From: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>
To: "Matt Arnilo S(dot) Baluyos \(Mailing Lists\)" <matt(dot)baluyos(dot)lists(at)gmail(dot)com>, pgsql-novice(at)postgresql(dot)org
Subject: Re: Sorting distinct dates by year and month respectively
Date: 2006-06-07 15:01:38
Message-ID: 20060607150138.12804.qmail@web31815.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice


> Now, I'd like to get only the year and month parts but I want them
> ordered by year and then by month in ascending order. I'm using the
> query below, but it doesn't order the results the way I want it.
>
> gsin=> SELECT DISTINCT date_part('year', article_pubdate),
> date_part('month', article_pubdate) FROM articles GROUP BY
> date_part('year', article_pubdate), date_part('month',
> article_pubdate) ORDER BY date_part('year', article_pubdate),
> date_part('month', article_pubdate) DESC;
OOPS,

Sorry,

I previous email, did not really answer your question.

your year column is sorted ascending ( small to great).
your month column is sorted decending ( great to small).

you should specify asc or desc for both columns to insure the desired result.

Regards,

Richard Broersma Jr.

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Matt Arnilo S. Baluyos (Mailing Lists) 2006-06-07 18:36:22 Re: Sorting distinct dates by year and month respectively
Previous Message Tom Lane 2006-06-07 14:56:20 Re: Sorting distinct dates by year and month respectively