From: Stephan Szabo <sszabo@megazone.bigpanda.com>
To: Michiel Lange <michiel@minas.demon.nl>
Cc: pgsql-admin@postgresql.org
Subject: Re: I feel a bit dumb, but getting a bit clueless
Date: Fri, 7 Nov 2003 07:32:12 -0800 (PST)
Message-ID: <20031107072447.L82577@megazone.bigpanda.com> (raw)
In-Reply-To: <3FAB9036.6000900@minas.demon.nl>
References: <3FAB9036.6000900@minas.demon.nl>
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.
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: sszabo@megazone.bigpanda.com, michiel@minas.demon.nl
Subject: Re: I feel a bit dumb, but getting a bit clueless
In-Reply-To: <20031107072447.L82577@megazone.bigpanda.com>
References: <3FAB9036.6000900@minas.demon.nl> <20031107072447.L82577@megazone.bigpanda.com>
* 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