Re: help with "delete joins" - Mailing list pgsql-sql

From Stephan Szabo
Subject Re: help with "delete joins"
Date
Msg-id 20030630153445.C40392-100000@megazone23.bigpanda.com
Whole thread Raw
In response to help with "delete joins"  (Robert Treat <rtreat@webmd.net>)
List pgsql-sql
On 30 Jun 2003, Robert Treat wrote:

> create table foo (a int, b int, c int, d text);
>
> create table bar (a int, b int, c int);
>
> insert into foo values (1,2,3,'a');
> insert into foo values (1,2,4,'A');
> insert into foo values (4,5,6,'b');
> insert into foo values (7,8,9,'c');
> insert into foo values (10,11,12,'d');
>
> insert into bar values (1,2,3);
> insert into bar values (7,8,9);
> insert into bar values (10,11,12);
>
> what i want to do is:
>
> delete * from foo where not (foo.a = bar.a and foo.b=bar.b and
> foo.c=bar.c) ;
>
> so i end up with
>
> postgres=# select * from foo;
>  a | b | c | d
> ---+---+---+---
>  1 | 2 | 4 | A
>  4 | 5 | 6 | b
> (2 rows)
>
> but thats not valid sql, is there some way to accomplish this?

Maybe something like:

delete from foo where exists (select * from bar wherebar.a=foo.a and bar.b=foo.b and bar.c=foo.c);



pgsql-sql by date:

Previous
From: Robert Treat
Date:
Subject: help with "delete joins"
Next
From: Robert Treat
Date:
Subject: Re: help with "delete joins"