Re: Help with query involving aggregation and joining.

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: vampyre5(at)yahoo(dot)com, pgsql-sql(at)postgresql(dot)org
Subject: Re: Help with query involving aggregation and joining.
Date: 2003-02-23 20:24:47
Message-ID: 200302231224.47583.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Bruno Wolff III 2003-02-23 20:45:42 Re: Help with query involving aggregation and joining.
Previous Message Josh Berkus 2003-02-23 20:19:08 Re: [SQL] 7.3 GROUP BY differs from 7.2