Re: Difference between IN and JOIN

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Markus Bertheau <twanger(at)bluetwanger(dot)de>
Cc: pgsql-sql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Difference between IN and JOIN
Date: 2004-10-04 14:17:16
Message-ID: 20688.1096899436@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Markus Bertheau <twanger(at)bluetwanger(dot)de> writes:
> I lately wondered if there is a difference between a JOIN and a IN in
> queries similar to the following:

> SELECT f1 FROM t1 JOIN t2 ON (t.f2 = t2.f2) WHERE t2.f3 = x

> SELECT f1 FROM t1 WHERE t1.f2 IN (SELECT f2 FROM t2 WHERE f3 = x)

> As I see it there's no semantic difference between the two.

There's plenty of difference, if t2 contains repeated occurrences of f2
values.

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Markus Bertheau 2004-10-04 14:23:49 Re: Difference between IN and JOIN
Previous Message Magnus Hagander 2004-10-04 11:39:31 Re: Concurrency problem