Problems with select statement

From: Lynna Landstreet <lynna(at)spidersilk(dot)net>
To: PgSQL-Novice <pgsql-novice(at)postgresql(dot)org>
Subject: Problems with select statement
Date: 2006-01-19 11:11:36
Message-ID: BFF4DE18.24452%lynna@spidersilk.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

OK, this may be just my brain being foggy because it's late at night and
I've been working on this project too long, but I have a SELECT statement
that's not doing what I want, and I can't figure out why.

The statement is:

SELECT * FROM users_to_plans p, users u, relation_types r, languages l
WHERE p.plan_id = [some plan number here]
AND p.user_id = u.user_id
AND u.language_id = l.language_id
AND u.relation_type_id = r.relation_type_id
ORDER BY u.relation_type_id

What I want it to do:

Bring up all the users who are included in a particular plan (i.e. all the
entries in users_to_plans for that plan number) and for each one, also bring
up their language preference and their relationship to the primary contact
for that plan. Each user has a relation_type_id listed that corresponds to a
particular kind of relationship in the relations table (primary contact,
spouse, child, etc.) and a language_id that corresponds to one of the
languages in the language table.

What it's doing instead:

Bringing up only the primary contact, even though there are more users
listed under that plan in the users to plans table. When I tried cutting out
the relationship and language, it worked fine, but something about including
those - either of them; I tried it with each one individually as well as
together - makes it bring up only one result.

Does anyone know why it's doing this, and how I might rephrase this so that
it works properly? I suppose I could just do separate queries of the
languages and relations tables for each user that comes up, but that seems
messy and inefficient. There's got to be a way to do it with just one query
statement...

Any assistance would be appreciated.

Lynna

--
Spider Silk Design - http://www.spidersilk.net
509 St Clair W Box 73576, Toronto ON Canada M6C 1C0
Tel 416.651.2899 - Toll Free 1.866.651.2899 - Cell 416.873.9289

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Stephan Szabo 2006-01-19 14:55:08 Re: Problems with select statement
Previous Message Anthony Presley 2006-01-18 23:07:39 Re: Huge size of Data directory