X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 7A3F99FB1EA for ; Thu, 14 Sep 2006 04:13:37 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 40290-01 for ; Thu, 14 Sep 2006 04:13:23 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.logix-tt.com (mail.logix-tt.com [212.211.145.186]) by postgresql.org (Postfix) with ESMTP id CCD369FA36A for ; Thu, 14 Sep 2006 04:13:26 -0300 (ADT) Received: from kingfisher.intern.logix-tt.com (p549D223A.dip0.t-ipconnect.de [84.157.34.58]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.logix-tt.com (Postfix) with ESMTP id 1B6C965977; Thu, 14 Sep 2006 09:15:41 +0200 (CEST) Received: from [127.0.0.1] (localhost [127.0.0.1]) by kingfisher.intern.logix-tt.com (Postfix) with ESMTP id 82BEE18587DAB; Thu, 14 Sep 2006 09:13:24 +0200 (CEST) Message-ID: <45090114.5020500@logix-tt.com> Date: Thu, 14 Sep 2006 09:13:24 +0200 From: Markus Schaber Organization: Logical Tracking and Tracing International AG, Switzerland User-Agent: Thunderbird 1.5.0.5 (X11/20060812) MIME-Version: 1.0 To: Javanesevn Cc: pgsql-sql@postgresql.org Subject: Re: How to delete multiple records References: <4508F1A7.3040907@sangtao.net> In-Reply-To: <4508F1A7.3040907@sangtao.net> X-Enigmail-Version: 0.94.0.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.172 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200609/96 X-Sequence-Number: 26307 Hi, Javanesevn, Javanesevn wrote: > I execute this query on below: > > delete from PRODUCT > where exists ( > select > product_id, item_id > from PRODUCT > where > research_date < '2006-01-01' > ) > this query deleted all records data in PRODUCT table. The subquery > return only some records. Yes, that's correct. You don't have any interconnection between the inner and the outer query. So, for every outer row, there exists an inner row which has research_date < '2006-01-01'. > Tell me about other idea? and What's wrong from this query. For this simple case, why don't you do: DELETE FROM PRODUCT WHERE research_date < '2006-01-01' Or do you want to delete all entries for products that have at least one entry with a matching research date? Then go along something like DELETE FROM product WHERE EXISTS ( SELECT * from product innr WHERE research_date < '2006-01-01' AND product_id = innr.product_id AND item_id = innr.item_id ); HTH, Markus -- Markus Schaber | Logical Tracking&Tracing International AG Dipl. Inf. | Software Development GIS Fight against software patents in Europe! www.ffii.org www.nosoftwarepatents.org