From: | "Josh Berkus" <josh(at)agliodbs(dot)com> |
---|---|
To: | "Brian Johnson" <bjohnson(at)jecinc(dot)on(dot)ca>, <pgsql-novice(at)postgresql(dot)org> |
Subject: | Re: Adding two select statements together |
Date: | 2002-04-16 15:31:41 |
Message-ID: | web-1372465@davinci.ethosmedia.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Brian,
> I have three tables for entering time data for projects.
>
> The three tables are timeentries, projects, and projectstatus.
> timeentries
> references the project id from projects and projects references the
> projectstatus table
This sounds nightmarish ... do you have any design control over the
database?
> I want to select all of the projects that aren't defined as
> "Inactive" like
> so
> SELECT testproject.*, teststatus.name
> FROM testproject INNER JOIN teststatus ON testproject.status =
> teststatus.id
> WHERE (teststatus.name<>"Inactive");
>
>
> but I also want to include any projects that are referenced by the
> timeentries between two dates (without having duplicate project
> listings)
What's wrong with changing the where clause to:
WHERE (teststatus.name<>"Inactive")
OR EXISTS ( SELECT timeentries.projectid
FROM timeentries
WHERE timeentries.dateentered BETWEEN $start_date AND $end_date
AND projectid = testproject.projectid);
You should pick up a SQL book to learn about more clauses like EXISTS.
See:
http://techdocs.postgresql.org/techdocs/bookreviews.php
For listings of a few books.
-Josh Berkus
From | Date | Subject | |
---|---|---|---|
Next Message | Juliet May | 2002-04-16 16:30:42 | Working with multiple selects? |
Previous Message | Brian Johnson | 2002-04-16 15:25:06 | Adding two select statements together |