pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kai Hessing <kai.hessing@hobsons.de>
To: pgsql-sql@postgresql.org
Subject: Advanced SELECT
Date: Wed, 23 Feb 2005 14:43:25 +0100
Message-ID: <383fk1F5hq3hhU1@individual.net> (raw)

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.)



view thread (5+ messages)  latest in thread

Message-ID: <383fk1F5hq3hhU1@individual.net>
Permalink:  ../383fk1F5hq3hhU1@individual.net/
Also on:    postgresql.org/message-id/383fk1F5hq3hhU1@individual.net

 · 

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-general@postgresql.org
  Cc: kai.hessing@hobsons.de, pgsql-sql@postgresql.org
  Subject: Re: Advanced SELECT
  In-Reply-To: <383fk1F5hq3hhU1@individual.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