X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 5820CD1B533 for ; Fri, 7 Nov 2003 15:32:44 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 34037-04 for ; Fri, 7 Nov 2003 11:32:17 -0400 (AST) Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by svr1.postgresql.org (Postfix) with ESMTP id 502E3D1B53E for ; Fri, 7 Nov 2003 11:32:13 -0400 (AST) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 8C2C035384; Fri, 7 Nov 2003 07:32:12 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 8AB373537F; Fri, 7 Nov 2003 07:32:12 -0800 (PST) Date: Fri, 7 Nov 2003 07:32:12 -0800 (PST) From: Stephan Szabo To: Michiel Lange Cc: pgsql-admin@postgresql.org Subject: Re: I feel a bit dumb, but getting a bit clueless In-Reply-To: <3FAB9036.6000900@minas.demon.nl> Message-ID: <20031107072447.L82577@megazone.bigpanda.com> References: <3FAB9036.6000900@minas.demon.nl> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200311/120 X-Sequence-Number: 11108 On Fri, 7 Nov 2003, Michiel Lange wrote: > I am certainly not awake, that I have troubles with a simple thing like > this, but there it is.... > > I have three tables: Names(NameID INT4 PRIM INDEX, Name VARCHAR(30)), > Groups(GroupID INT4 PRIM INDEX, Group VARCHAR(30)) > And a table Members(NameID,GroupID) PRIM INDEX ON (NameID, GroupID) > > Now I put some data in all three tables, first created some Names (a > grand total of 4) and a few groups (a grand total of 6) > And Members like this (NameID, GroupID) > 1, 1 > 1, 2 > 1, 3 > 2, 1 > 2, 4 > 2, 5 > 3, 2 > 3, 6 > 4, 1 > > Now I want to show essentially the Members table, but the numbers should > be replaced by the Names that go with the ID. > When I try this query: > SELECT "Name", "Group" FROM "Names", "Groups" RIGT JOIN "Members" ON > 'Names.NameID' = 'Members.NameID' AND 'Groups.GroupID' = 'Members.GroupID'; I doubt this is the actual query since at the very least RIGHT is misspelled. However, your ON conditions are testing constant strings, not columns (single quotes rather than double quotes) and you cannot put the Names to Members comparison in the ON because that'll be an error unless you did something like: SELECT "Name", "Group" FROM "Members" LEFT JOIN "Names" ON "Names"."NameID" = "Members"."NameID" LEFT JOIN "Groups" ON "Groups"."GroupID" = "Members"."GroupID"; The first join may be intended to be INNER if you want to drop people from the output who don't have names. If you want to drop output rows where neither existed you can add where "Name" is not null or "Group" is not null to the end.