From: | Reinoud van Leeuwen <reinoud(dot)v(at)n(dot)leeuwen(dot)net> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: How to delete multiple records |
Date: | 2006-09-14 07:09:29 |
Message-ID: | 20060914070929.GC60441@spoetnik.xs4all.nl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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(dot)v(at)n(dot)leeuwen(dot)net
http://www.xs4all.nl/~reinoud
__________________________________________________
From | Date | Subject | |
---|---|---|---|
Next Message | Markus Schaber | 2006-09-14 07:13:24 | Re: How to delete multiple records |
Previous Message | Javanesevn | 2006-09-14 06:07:35 | How to delete multiple records |