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

Re: Query combination query. (fwd)

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: john-paul delaney <jp(at)justatest(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Query combination query. (fwd)
Date: 2005-02-22 15:01:28
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
On Tue, Feb 22, 2005 at 15:54:47 +0100,
  john-paul delaney <jp(at)justatest(dot)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.

In response to


pgsql-novice by date

Next:From: Tom LaneDate: 2005-02-22 15:20:55
Subject: Re: Function with record type as argument
Previous:From: john-paul delaneyDate: 2005-02-22 14:54:47
Subject: Re: Query combination query. (fwd)

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