pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
To: vampyre5@yahoo.com
To: pgsql-sql@postgresql.org
Subject: Re: Help with query involving aggregation and joining.
Date: Sun, 23 Feb 2003 12:24:47 -0800
Message-ID: <200302231224.47583.josh@agliodbs.com> (raw)
In-Reply-To: <20030223190227.21867.qmail@web80401.mail.yahoo.com>
References: <20030223190227.21867.qmail@web80401.mail.yahoo.com>

Eddie,

> My requirements involve several large tables. I have
> simplied scenario into the follow two fictional tables
> which describes the same requirements.

Keep in mind that a simplified example may not solve your real problem ...

> Basically I would like to display the latest
> submission for each course in a table as shown below,
> order by name of the courses.
>
> Query Results:
> ==============
>  id | courseId |  name    | submission
> ---------------------------------------
>  4  |  102     | Chemisty | 2002-02-22
>  3  |  104     | Maths    | 2002-04-30
>  1  |  101     | Physics  | 2002-01-20

Easy:

SELECT id, courseid, name, max(submission) as submission
FROM history JOIN courses ON history.courseid = course.id
GROUP BY id, courseid, name
ORDER BY name

And as such, I suspect that your real case is more complicated than the above 
...

-- 
Josh Berkus
Aglio Database Solutions
San Francisco



view thread (12+ messages)  latest in thread

Message-ID: <200302231224.47583.josh@agliodbs.com>
Permalink:  ../200302231224.47583.josh@agliodbs.com/
Also on:    postgresql.org/message-id/200302231224.47583.josh@agliodbs.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: josh@agliodbs.com, vampyre5@yahoo.com
  Subject: Re: Help with query involving aggregation and joining.
  In-Reply-To: <200302231224.47583.josh@agliodbs.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox