Re: where clauses and multiple tables - Mailing list pgsql-general

From Yaroslav Tykhiy
Subject Re: where clauses and multiple tables
Date
Msg-id 0D71ADA4-41CE-446A-8F0E-5E8F590E9224@barnet.com.au
Whole thread Raw
In response to Re: where clauses and multiple tables  (David W Noon <dwnoon@ntlworld.com>)
Responses Re: where clauses and multiple tables  (John R Pierce <pierce@hogranch.com>)
List pgsql-general
On 09/09/2009, at 9:02 AM, David W Noon wrote:

> 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.

By the way, folks, do you think there may be performance gain or loss
from rewriting this with an explicit JOIN?  E.g.:

SELECT DISTINCT foo.foo_id, foo.name FROM foo JOIN bar ON foo.bar_id =
bar.bar_id WHERE bar.name='martini';

Thanks!

Yar

pgsql-general by date:

Previous
From: miller_2555
Date:
Subject: Re: Using symbolic links with tablespaces
Next
From: Yaroslav Tykhiy
Date:
Subject: Re: Can I Save images in postgres?