Re: Query combination query. (fwd) - Mailing list pgsql-novice

From Bruno Wolff III
Subject Re: Query combination query. (fwd)
Date
Msg-id 20050222150128.GG22550@wolff.to
Whole thread Raw
In response to Re: Query combination query. (fwd)  (john-paul delaney <jp@justatest.com>)
Responses Re: Query combination query. (fwd)  (john-paul delaney <jp@justatest.com>)
List pgsql-novice
On Tue, Feb 22, 2005 at 15:54:47 +0100,
  john-paul delaney <jp@justatest.com> wrote:
>
> Given Sean's answer above, I then managed the simple part to get the author
> name from another table, but was stumped when I thought it
> would be better to return the created date of the last message (having the same
> topic_id) rather than the first one.  The last message can be found in
> either of two ways:
>         (1) the latest 'created' for a topic_id or
>         (2) the highest 'topic_seq' number for a topic id.
>
> I've failed miserably in my attempts - any enlightenment greatly appreciated.

The standard way to do this is to use the max function and select the
row that matches this value.

However the nonstandard DISTINCT ON construct is a better way to go if
you don't need to be portable.

pgsql-novice by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: Perl DBI connection to Postgres
Next
From: john-paul delaney
Date:
Subject: Re: Query combination query. (fwd)