From: Alexei Chetroi <lexoid@lexa.uniflux-line.net>
Cc: Pgsql-Sql <pgsql-sql@postgresql.org>
Subject: SQL subqueries newbie help
Date: Sat, 6 Sep 2003 14:07:09 +0300
Message-ID: <20030906110709.GA13384@uniflux-line.net> (raw)
Hi All,
I need a little help regarding writing some subqueries. For example I
have a table "items" which contains columns: itemid, description; and
another table "events" with columns: itemid, date, event. events.itemid
references items.itemid. Table events contains events regarding some
itemid's from table items, so there could be multiple events regarding
one item from items table. for example:
Table: items
itemid description
1 Lamp
2 Desk
3 HiFi
Table: events
itemid event date
1 purchase 2003-01-01
1 repair 2003-01-03
1 repair 2003-02-05
2 purchase 2003-02-01
3 HiFi 2003-02-01
I'd like to write a query which returns following information regarding
each item: item, date of very first event, very last event.
Is this possible? I think I can write several SELECT queries and
procces them by an application or possibly write some procedure, but
what is better solution?
PS: are there any books regarding complex SQL queries in electronic
format?
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: lexoid@lexa.uniflux-line.net
Subject: Re: SQL subqueries newbie help
In-Reply-To: <20030906110709.GA13384@uniflux-line.net>
* 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