Re: SQL help

From: "Josh Berkus" <josh(at)agliodbs(dot)com>
To: "Chad Thompson" <chad(at)weblinkservices(dot)com>, "pgsql-novice" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: SQL help
Date: 2002-12-13 01:01:29
Message-ID: web-2279498@davinci.ethosmedia.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Chad,

> I have a problem that I know can be solved if I can only explain it
> properly.

<grin> Personally, I frequently find that as soon as I explain a
problem clearly, the answer becomes self-evident.

> I have 3 tables, clients, projects and list_of_lists. Each has an Id
> field
>
> select c.id as client_id, p.id as project_id, l.id as
> list_of_lists_id
> from clients c inner join list_of_lists l on c.id = l.client_id
> inner join projects p on c.id = p.client_id
>
> This gives me every client, their projects and every list. I want
> most of this but not all.
>
> select c.id as client_id, p.id as project_id, l.id as
> list_of_lists_id
> from clients c inner join projects p on c.id = p.client_id
> inner join list_of_lists l on p.id = l.project_id
>
> This gives me only those lists that are associated with specific
> projects.
> If you havent guessed already Im trying to recover from bad database
> design.
>
> So what Im looking for is a list, like that of the first query, but
> if a project only has specific lists associated with it, I want only
> those from the second query.

Hmmm... you're saying that you want all lists for a client if their
projects have no specific lists, but the lists for the projects if they
do? Or something else?

And, btw, Postgres doesn't use the "inner join" syntax. Are you sure
that you're using PostgreSQL?

-Josh Berkus

In response to

  • SQL help at 2002-12-12 18:28:09 from Chad Thompson

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Chad Thompson 2002-12-13 01:08:18 Re: SQL help
Previous Message Chad Thompson 2002-12-12 18:28:09 SQL help