Re: Quetions on Joins

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Alex <alex(at)meerkatsoft(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Quetions on Joins
Date: 2003-08-31 18:15:19
Message-ID: 20030831111037.K94333-100000@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Mon, 1 Sep 2003, Alex wrote:

> Hi,
>
> I have a query where I want to filter out records from table_a if a
> field in table_a matches in table table_b. Basically table_b defines the
> filter.

Well something like one of the following should work depending
on how you want to treat nulls and such (and performance varies in
postgresql by version for each of the options):

SELECT a.value_one FROM table_a AS A where NOT EXISTS
(select 1 from table_b AS B WHERE A.value_two=B.value_two);
SELECT a.value_one FROM table_a AS A where A.value_two NOT IN
(select value_two from table_b);
SELECT a.value_one FROM table_a AS A LEFT OUTER JOIN
table_b AS B ON (a.value_two=B.value_two) WHERE B.value_two IS NULL;

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2003-08-31 18:21:20 Re: SELECT Question
Previous Message Alex 2003-08-31 17:03:52 SELECT Question