where clauses and multiple tables

From: Scott Frankel <frankel(at)circlesfx(dot)com>
To: PostgreSQL List <pgsql-general(at)postgresql(dot)org>
Subject: where clauses and multiple tables
Date: 2009-09-08 21:25:20
Message-ID: 5A89DD8A-B363-4643-B21A-EEC0C56B7E97@circlesfx.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Hello,

Is it possible to join tables in the where clause of a statement?

I ask because I have a situation where I only have access to the where
clause of a select statement on a single table, yet I want to perform
a join on multiple tables. eg:

Given a statement as follows:

SELECT foo.foo_id, foo.name
FROM foo, bar
WHERE foo.bar_id = bar.bar_id
AND bar.name = 'martini';

I'm looking for a way to recast it so that the select and from clauses
still refer to a single table and the join referencing the second
table occurs in the where clause. For example, something like this:

SELECT foo.foo_id, foo.name
FROM foo
WHERE (SELECT * FROM foo, bar WHERE ...)
foo.bar_id = bar.bar_id
AND bar.name = 'martini';

I've explored the "where exists" clause, but that's not supported by
the application toolkit I'm using. AFAIK, I've only got access to
where ...

Thanks in advance!
Scott

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard Broersma 2009-09-08 22:26:00 Transaction Strategies for Natural Primary Keys & Cascading Updates
Previous Message miller_2555 2009-09-08 20:45:55 Using symbolic links with tablespaces