where clauses and selects

From: Scott Frankel <leknarf(at)pacbell(dot)net>
To: PostgreSQL List <pgsql-general(at)postgresql(dot)org>
Subject: where clauses and selects
Date: 2009-09-08 17:29:17
Message-ID: 5F849E7C-7FD3-4BBD-BF00-4BF1F63F79E8@pacbell.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Hello,

Is it possible to perform a select in the where clause of a statement?

I have a situation where I've got one arm tied behind my back: I can
only have a single table in the select and from clauses, but the where
clause appears to be freed from that restriction.

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
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 it'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 David Fetter 2009-09-08 17:30:21 Statistics and PostgreSQL: Streaming Webcast tonight
Previous Message Andrus 2009-09-08 16:29:07 pg_dump exists without any message when running from windows task scheduler