Re: Question on a select

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Madison Kelly <linux(at)alteeve(dot)com>
Cc: PgSQL General List <pgsql-general(at)postgresql(dot)org>
Subject: Re: Question on a select
Date: 2005-01-02 04:42:06
Message-ID: 20050102044206.GA15950@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, Jan 01, 2005 at 22:32:17 -0500,
Madison Kelly <linux(at)alteeve(dot)com> wrote:
> Hi all,
>
> This is my first post here so please let me know if I miss any list
> guidelines. :)
>
> I was hoping to get some help, advice or pointers to an answer for a
> somewhat odd (to me at least) SELECT. What I am trying to do is select
> that values from one table where matching values do not exist in another
> table.
>
> For example:
>
> Let's say 'table_a' has the columns 'a_name, a_type, a_dir,
> a_<others>' and 'table_b' has the columns 'b_name, b_type, b_dir,
> b_<others>' where 'others' are columns unique to each table. What I need
> to do is select all the values in 'a_name, a_type, a_dir' from 'table_a'
> where there is no matching entries in "table_b's" 'b_name, b_type, b_dir'.

SELECT a_name, a_type, a_dir, a_<others> FROM table_a
WHERE a_name, a_type, a_dir NOT IN (
SELECT b_name, b_type, b_dir FROM table_b)
;

In pre 7.4 versions or if there are NULLs in the key columns for table_b
then you probably want to use NOT EXISTS (with a moodified WHERE clause)
instead on NOT IN.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Michael Fuhr 2005-01-02 05:25:02 Re: Function Parameters
Previous Message Vincent Hikida 2005-01-02 04:18:23 Re: Question on a select