X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 852103109AD for ; Mon, 30 Jun 2003 22:36:58 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 04870-04 for ; Mon, 30 Jun 2003 19:36:47 -0300 (ADT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) by svr1.postgresql.org (Postfix) with ESMTP id A2100310982 for ; Mon, 30 Jun 2003 19:36:47 -0300 (ADT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 5C9BAD627; Mon, 30 Jun 2003 15:36:47 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 5249E5C0B; Mon, 30 Jun 2003 15:36:47 -0700 (PDT) Date: Mon, 30 Jun 2003 15:36:47 -0700 (PDT) From: Stephan Szabo To: Robert Treat Cc: Subject: Re: help with "delete joins" In-Reply-To: <1057011998.24310.348.camel@camel> Message-ID: <20030630153445.C40392-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Archive-Number: 200306/350 X-Sequence-Number: 14108 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 where bar.a=foo.a and bar.b=foo.b and bar.c=foo.c);