X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6F61D9DCDB2 for ; Fri, 24 Mar 2006 13:28:47 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 83899-08 for ; Fri, 24 Mar 2006 13:28:46 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from peufeu.com (boutiquenumerique.com [82.67.9.10]) by postgresql.org (Postfix) with ESMTP id E082D9DCDA5 for ; Fri, 24 Mar 2006 13:28:44 -0400 (AST) Received: (qmail 28244 invoked from network); 24 Mar 2006 18:29:26 +0100 Received: from boutiquenumerique.com (HELO apollo13) (82.67.9.10) by boutiquenumerique.com with SMTP; 24 Mar 2006 18:29:26 +0100 Date: Fri, 24 Mar 2006 18:29:25 +0100 To: "D'Arcy J.M. Cain" , "Todd Kennedy" Subject: Re: Question about One to Many relationships Cc: pgsql-sql@postgresql.org References: <226d83de0603240852q54af3512odfce218d69718c8b@mail.gmail.com> <20060324120142.d3fdf477.darcy@druid.net> From: PFC Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID: In-Reply-To: <20060324120142.d3fdf477.darcy@druid.net> User-Agent: Opera M2/8.51 (Linux, build 1462) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.111 required=5 tests=[AWL=0.111, UPPERCASE_25_50=0] X-Spam-Score: 0.111 X-Spam-Level: X-Archive-Number: 200603/382 X-Sequence-Number: 24728 >> And I want to link the band to the album, but, if the album is a >> compilation it'll be linked to multiple band.ids, so i can't just add >> a column like: For a compilation, you should link a band to a track, not an album. This opens another can of worms... I would use the following tables : CREATE TABLE albums ( id SERIAL PRIMARY KEY ... other data ); CREATE TABLE tracks ( id SERIAL PRIMARY KEY album_id INTEGER NOT NULL REFERENCES albums( id ) ... other data ): CREATE TABLE artists ( id SERIAL PRIMARY KEY ... other data ); -- A role is : composer, performer, singer, DJ, compilation maker, lead violonist, etc. CREATE TABLE roles ( id SERIAL PRIMARY KEY ... other data ); CREATE TABLE track_artists ( track_id INTEGER NOT NULL REFERENCES tracks( id ) role_id INTEGER NOT NULL REFERENCES roles( id ) artist_id INTEGER NOT NULL REFERENCES artists( id ) ); And you may also with to specify main artists for an album : CREATE TABLE track_artists ( album_id INTEGER NOT NULL REFERENCES albums( id ) role_id INTEGER NOT NULL REFERENCES roles( id ) artist_id INTEGER NOT NULL REFERENCES artists( id ) ); You will then need a few LEFT JOINs and to get the artists for a track. It is interesting to know if the artist comes from the album or from the track. For instance the composer of the whole album might invite a guest singer on some tracks.