Re: where clauses and multiple tables

From: David W Noon <dwnoon(at)ntlworld(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: where clauses and multiple tables
Date: 2009-09-08 23:02:21
Message-ID: 20090909000221.36d0c6c9@dwnoon.ntlworld.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 8 Sep 2009 14:25:20 -0700, Scott Frankel wrote about [GENERAL]
where clauses and multiple tables:

>Is it possible to join tables in the where clause of a statement?
[snip]
>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';

Just use an IN predicate:

SELECT foo_id, name FROM foo
WHERE bar_id IN (SELECT bar_id FROM bar WHERE name = 'martini');

This is frequently called a semi-join.
--
Regards,

Dave [RLU #314465]
=======================================================================
david(dot)w(dot)noon(at)ntlworld(dot)com (David W Noon)
=======================================================================

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message miller_2555 2009-09-08 23:03:08 Re: where clauses and multiple tables
Previous Message Richard Broersma 2009-09-08 22:26:00 Transaction Strategies for Natural Primary Keys & Cascading Updates