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 5A2AC310AD7 for ; Mon, 30 Jun 2003 22:40:34 +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 06710-01 for ; Mon, 30 Jun 2003 19:40:23 -0300 (ADT) Received: from localhost.localdomain (unknown [65.217.53.66]) by svr1.postgresql.org (Postfix) with ESMTP id EA11C310AD4 for ; Mon, 30 Jun 2003 19:40:22 -0300 (ADT) Received: from thorn.mmrd.com (thorn.mmrd.com [172.25.10.100]) by localhost.localdomain (8.12.8/8.12.8) with ESMTP id h5UNcB4i015400 for ; Mon, 30 Jun 2003 19:38:11 -0400 Received: from gnvex001.mmrd.com (gnvex001.mmrd.com [192.168.3.55]) by thorn.mmrd.com (8.11.6/8.11.6) with ESMTP id h5UMeMZ06266 for ; Mon, 30 Jun 2003 18:40:22 -0400 Received: from camel.mmrd.com ([172.25.5.213]) by gnvex001.mmrd.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id MTKBPRN3; Mon, 30 Jun 2003 18:40:21 -0400 Subject: Re: help with "delete joins" From: Robert Treat To: Robert Treat Cc: pgsql-sql@postgresql.org In-Reply-To: <1057011998.24310.348.camel@camel> References: <1057011998.24310.348.camel@camel> Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.0.8 Date: 30 Jun 2003 18:40:22 -0400 Message-Id: <1057012822.24304.360.camel@camel> Mime-Version: 1.0 X-Archive-Number: 200306/351 X-Sequence-Number: 14109 On Mon, 2003-06-30 at 18:26, 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? > ok, i have a solution from the other end: create table baz as select * from foo except (select foo.* from foo,bar where foo.a = bar.a and foo.b=bar.b and foo.c=bar.c); but i'd still be interested in a delete based method :-) Robert Treat -- Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL