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 89F243109C0 for ; Tue, 1 Jul 2003 13:43:22 +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 67860-05 for ; Tue, 1 Jul 2003 10:43:11 -0300 (ADT) Received: from localhost.localdomain (unknown [65.217.53.66]) by svr1.postgresql.org (Postfix) with ESMTP id 8BBC3310AA9 for ; Tue, 1 Jul 2003 10:43:11 -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 h61Ef64i017330; Tue, 1 Jul 2003 10:41:06 -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 h61Dh7Z14934; Tue, 1 Jul 2003 09:43:08 -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 MTKBPTVP; Tue, 1 Jul 2003 09:43:05 -0400 Subject: Re: help with "delete joins" From: Robert Treat To: Josh Berkus , Stephan Szabo Cc: pgsql-sql@postgresql.org In-Reply-To: <200306301735.29482.josh@agliodbs.com> References: <1057011998.24310.348.camel@camel> <200306301735.29482.josh@agliodbs.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.0.8 Date: 01 Jul 2003 09:43:07 -0400 Message-Id: <1057066987.24310.383.camel@camel> Mime-Version: 1.0 X-Archive-Number: 200307/10 X-Sequence-Number: 14124 On Mon, 2003-06-30 at 20:35, Josh Berkus wrote: > Robert, > > > 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? > > Um, your example result doesn't match your pseudo-query. the end of a long day that started with 4 hours of sleep... no wonder I couldn't get my head around this one. I actually did want the results of the psuedo query, not the results I posted :-\ > Assuming that you > want to delete everything that DOES match, not everything that DOESN'T, do: > > DELETE FROM foo > WHERE EXISTS ( SELECT bar.a FROM bar > WHERE bar.a = foo.a AND bar.b = foo.b > AND bar.c = foo.c ); I was almost there with my original query... a NOT on your/stephan's query gets me what I really want. :-) Thanks guys. Robert Treat -- Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL