From: no.spam@address.com
To: pgsql-sql@postgresql.org
Subject: Denormalizing during select
Date: Mon, 24 Feb 2003 17:18:24 GMT
Message-ID: <u3kk5v4i276aqv2hv22pn6jh4t3a2ev08g@4ax.com> (raw)
I have two tables (A and B) in a one-to-many relationship. When
retrieving data from one table (A), I need to denormalize the tables
during a select so that values of a column in the many table (B)
appear as a list in one field of the output. E.g.:
create table one_table (
name varchar(20),
age integer,
--
constraint one_table_pk
primary key (name)
);
create table many_table (
name varchar(20),
property varchar(15),
--
constraint many_table_pk
primary key (name, property),
constraint many_table_fk
foreign key (name) references one_table (name)
);
So one_table could contain:
name age
---- ---
Mickey Mouse 50
Donald Duck 60
Goofy 45
and many_table could contain:
name property
---- --------
Mickey Mouse Small
Mickey Mouse Black
Mickey Mouse Squeaks
Donald Duck Quacks
The query I'm trying to write would have as output something like:
name age properties
---- --- ----------
Mickey Mouse 50 Small, Black, Squeaks
Donald Duck 60 Quacks
Goofy 45 <null>
Could somebody please help point me in the right direction? I imagine
this is a common need...
Thanks,
...Edmund.
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: no.spam@address.com
Subject: Re: Denormalizing during select
In-Reply-To: <u3kk5v4i276aqv2hv22pn6jh4t3a2ev08g@4ax.com>
References: <u3kk5v4i276aqv2hv22pn6jh4t3a2ev08g@4ax.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