Re: Index Usage using IN - Mailing list pgsql-performance

From Jeffrey W. Baker
Subject Re: Index Usage using IN
Date
Msg-id 1138825699.8376.8.camel@toonses.gghcwest.com
Whole thread Raw
In response to Re: Index Usage using IN  ("Jeffrey W. Baker" <jwbaker@acm.org>)
List pgsql-performance
On Wed, 2006-02-01 at 12:22 -0800, Jeffrey W. Baker wrote:
> On Thu, 2006-02-02 at 09:12 +1300, Ralph Mason wrote:
> > Hi,
> >
> > I have 2 tables both have an index on ID (both ID columns are an oid).
> >
> > I want to find only only rows in one and not the other.
> >
> > Select ID from TableA where ID not IN ( Select ID from Table B)
>
> Have you considered this:
>
> SELECT ID from TableA EXCEPT Select ID from Table B

Alternately:

   SELECT a.ID
     FROM TableA AS a
LEFT JOIN TableB AS b
       ON a.ID = b.ID
    WHERE b.ID IS NULL

-jwb

pgsql-performance by date:

Previous
From: "Kevin Grittner"
Date:
Subject: Re: Planner reluctant to start from subquery
Next
From: Tom Lane
Date:
Subject: Re: Planner reluctant to start from subquery