Received: from localhost (uranus.hub.org [200.46.204.60]) by postgresql.org (Postfix) with ESMTP id 741B39FA221 for ; Wed, 15 Nov 2006 04:32:37 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.60]) (amavisd-new, port 10024) with ESMTP id 83091-06 for ; Wed, 15 Nov 2006 04:32:35 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from aa016msg.fastweb.it (aa016msg.fastweb.it [213.140.2.83]) by postgresql.org (Postfix) with ESMTP id 9FC949FA0CC for ; Wed, 15 Nov 2006 04:32:35 -0400 (AST) Received: from ms011msg.fastweb.it (10.31.40.27) by aa016msg.fastweb.it (7.3.105.6) id 4535D64500CDFAA9 for pgsql-sql@postgresql.org; Wed, 15 Nov 2006 09:31:00 +0100 Received: from [192.168.201.201] (89.97.40.40) by ms011msg.fastweb.it (7.2.070) id 443CC12D05591B37 for pgsql-sql@postgresql.org; Wed, 15 Nov 2006 09:32:30 +0100 From: Luca Ferrari To: pgsql-sql@postgresql.org Subject: sql problem with join Date: Wed, 15 Nov 2006 09:32:04 +0100 User-Agent: KMail/1.9.5 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200611150932.04806.fluca1978@infinito.it> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/154 X-Sequence-Number: 26806 Hi all, I've got a problem tryng to define a view with a few joins, I'll appreciate if someone could drive me in the definition of such query. I've got a table roleSkill that contains a row for each skill belonging to a defined role and with the desired competence level for such skill in such role: roleSkill = (id_role, id_skill, desired_level) PRIMARY KEY(id_role,id_skill) Then I've got a table peopleSkill with a row for each evaluated skill for a person (a skill in this case could not belong to a defined role): peopleSkill = (id_person,id_skill, evaluated_level) PRIMARY KEY(id_person,id_skill) Finally I've got an association between a person and a role: peopleRole = (id_person,id_role) PRIMARY KEY(id_person,id_role) Now I'd like to build a view that shows a row for each skill a person has (i.e. it has been evaluated) and should have (i.e. it is listed in the role). Initially I tried with something like: select p.*,r.* from roleSkill r JOIN peopleRole p on p.id_role=r.id_role /* this gives me all the roles a person has and all her skills */ LEFT JOIN peopleSkill s on s.id_skill = r.id_skill /* this should keep all the role skills and show the one evaluated */ So the first join should give me all the role played from a person, with its skills, the second join should take the evaluated skills and should keep the not evaluated (i.e., present only in roleSkill) rows. But this is not working, I see a lot of rows with the same role for the same person and I cannot find the error. Any clues? Thanks, Luca