X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id A11819FA21B for ; Thu, 14 Sep 2006 04:39:41 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 75313-09 for ; Thu, 14 Sep 2006 07:39:37 +0000 (UTC) X-Greylist: delayed 00:30:04.886815 by SQLgrey- Received: from spoetnik.xs4all.nl (spoetnik.xs4all.nl [213.84.24.58]) by postgresql.org (Postfix) with ESMTP id 8B3939FA15F for ; Thu, 14 Sep 2006 04:39:36 -0300 (ADT) Received: by spoetnik.xs4all.nl (Postfix, from userid 1000) id 03E391CCA3; Thu, 14 Sep 2006 09:09:29 +0200 (CEST) Date: Thu, 14 Sep 2006 09:09:29 +0200 From: Reinoud van Leeuwen To: pgsql-sql@postgresql.org Subject: Re: How to delete multiple records Message-ID: <20060914070929.GC60441@spoetnik.xs4all.nl> Mail-Followup-To: pgsql-sql@postgresql.org References: <4508F1A7.3040907@sangtao.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4508F1A7.3040907@sangtao.net> User-Agent: Mutt/1.4.2.1i X-message-flag: Warning! The sender of this mail thinks you should use a more secure email client. X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200609/97 X-Sequence-Number: 26308 On Thu, Sep 14, 2006 at 03:07:35PM +0900, Javanesevn wrote: > Dear all, > > 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. > Tell me about other idea? and What's wrong from this query. The easiest way is to do it like this: delete from PRODUCT where research_date < '2006-01-01' But if you really want to use a subquery, you want to relate it to the current record: delete from PRODUCT where product_in in ( select product_id from PRODUCT where research_date < '2006-01-01' ) In your example you just test if some records exist. They allways do, so the where clause evaluates to true for every row -- __________________________________________________ "Nothing is as subjective as reality" Reinoud van Leeuwen reinoud.v@n.leeuwen.net http://www.xs4all.nl/~reinoud __________________________________________________