Re: Aggregates - Mailing list pgsql-general

From Richard Huxton
Subject Re: Aggregates
Date
Msg-id 467A7B82.9030305@archonet.com
Whole thread Raw
In response to Aggregates  (Naz Gassiep <naz@mira.net>)
Responses Re: Aggregates  ("John D. Burger" <john@mitre.org>)
List pgsql-general
Naz Gassiep wrote:
> Hi,
>     If I have a table with users and a table with messages, is it
> possible to have a query that returns user.* as well as one extra column
> with the number of messages they have posted and the data and time of
> the last message? At the moment I am using a subquery to do this,
> however it seems suboptimal. Is there a better way?

Not really. You have three separate queries really:
1. User details
2. Total number of messages posted
3. Details on last message posted

Unless you have a messaging-summary table that you keep up-to-date with
triggers you're looking at a three-part query.
--
   Richard Huxton
   Archonet Ltd

pgsql-general by date:

Previous
From: "Albe Laurenz"
Date:
Subject: Re: Accent insensitive search
Next
From: "Dawid Kuroczko"
Date:
Subject: Re: [PGSQL 8.2.x] INSERT+INSERT