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 03281310D6E for ; Tue, 1 Jul 2003 19:13:48 +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 03414-05 for ; Tue, 1 Jul 2003 16:13:36 -0300 (ADT) Received: from www.postgresql.com (www.postgresql.com [64.117.225.209]) by svr1.postgresql.org (Postfix) with ESMTP id 97521310CFC for ; Tue, 1 Jul 2003 16:12:50 -0300 (ADT) Received: from wolff.to (wolff.to [66.93.249.74]) by www.postgresql.com (Postfix) with SMTP id 98F4BCF751F for ; Tue, 1 Jul 2003 11:43:19 -0300 (ADT) Received: (qmail 2423 invoked by uid 500); 1 Jul 2003 14:46:03 -0000 Date: Tue, 1 Jul 2003 09:46:03 -0500 From: Bruno Wolff III To: Robert Treat Cc: pgsql-sql@postgresql.org Subject: Re: help with "delete joins" Message-ID: <20030701144603.GA2410@wolff.to> Mail-Followup-To: Robert Treat , pgsql-sql@postgresql.org References: <1057011998.24310.348.camel@camel> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1057011998.24310.348.camel@camel> User-Agent: Mutt/1.5.4i X-Archive-Number: 200307/14 X-Sequence-Number: 14128 On Mon, Jun 30, 2003 at 18:26:38 -0400, Robert Treat wrote: > 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) ; For the case without not (which appears to be what you really want) you can pretty much do this. See below for sample input and output. 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); delete from foo where foo.a = bar.a and foo.b=bar.b and foo.c=bar.c; select * from foo; CREATE TABLE CREATE TABLE INSERT 92443 1 INSERT 92444 1 INSERT 92445 1 INSERT 92446 1 INSERT 92447 1 INSERT 92448 1 INSERT 92449 1 INSERT 92450 1 DELETE 3 a | b | c | d ---+---+---+--- 1 | 2 | 4 | A 4 | 5 | 6 | b (2 rows)