Advanced SELECT

From: Kai Hessing <kai(dot)hessing(at)hobsons(dot)de>
To: pgsql-sql(at)postgresql(dot)org
Subject: Advanced SELECT
Date: 2005-02-23 13:43:25
Message-ID: 383fk1F5hq3hhU1@individual.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

Hi Folks,

I hope to have found the right group for my question. I have difficult
sql-task. I try to describe it simple:

We have a table 'company' with a cid and a table 'sector' with a sid.
They are connected m:n via a third table 'company_sector' which contians
csid, cid and sid.

The normal clause would look like:

SELECT c.companyname, s.sectorname FROM company c, sector s,
company_sector cs WHERE cs.cid = c.cid AND cs.sid = s.sid ORDER BY
c.companyname;

This gives a result looking like this:

c.companyname | s.sector
---------------+------------------------
company1 | sectora
company1 | sectorb
company2 | sectora
company2 | sectorb
company2 | sectorc
company3 | sectora
company4 | sectorc

instead of this I want to have a listing like:

c.companyname | ??? (sectors)
---------------+------------------------
company1 | sectora, sectorb
company2 | sectora, sectorb, sectorc
company3 | sectora
company4 | sectorc

But I have no idea, how to write a SELECT-command that gives a listing
like this :( Maybe anyone can help *please*

*Thanks and greetings*
Kai...

--
GnuPG-PublicKey -> http://www.hobsons.de/pgp/kai_hessing.asc

Unzeitige Genuesse erzeugen Ekel.
(Demokrit, um 460 v. Chr.)

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Cristian Prieto 2005-02-23 13:56:04 Re: Help with a very newbie question...
Previous Message Jan Poslusny 2005-02-23 12:44:59 Re: Help with a very newbie question...

Browse pgsql-sql by date

  From Date Subject
Next Message Kai Hessing 2005-02-23 13:56:54 Software for database-visualisation
Previous Message mauro 2005-02-23 10:29:02 Postgres performance