Re: Aggregates

From: Richard Huxton <dev(at)archonet(dot)com>
To: Naz Gassiep <naz(at)mira(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Aggregates
Date: 2007-06-21 13:22:10
Message-ID: 467A7B82.9030305@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

  • Aggregates at 2007-06-21 11:01:42 from Naz Gassiep

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Dawid Kuroczko 2007-06-21 13:47:17 Re: [PGSQL 8.2.x] INSERT+INSERT
Previous Message Albe Laurenz 2007-06-21 13:18:50 Re: Accent insensitive search