Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Help with UPDATE

Re: Help with UPDATE

From: David Fitzjarrell <fitzjarrell_at_cox.net>
Date: 9 Nov 2004 07:25:23 -0800
Message-ID: <9711ade0.0411090725.4ebec9ca@posting.google.com>


Commente embedded.

aviles94_at_rcn.com (Enrique) wrote in message news:<ca9fa791.0411081940.575054d_at_posting.google.com>...
> I have two tables like these:
>
> Customer_Table
> ----------------------------
> Name Varchar2(20)
> Address Varchar2(20)
> Telephone Number
> Price Number
> Final_Price Number
>
> Discount_Table
> -----------------------------
> Name Varchar2(20)
> Address Varchar2(20)
> Telephone Number
> Discount Number
>
> I want to update the Final_Price column in the Customer table by
> joining both tables by Name, Address and Telephone and multiplying
> Price with Discount.
>
> I tried:
>
> Update Customer_Table a
> set a.final_price = a.price * (select b.discount from discount_table b
> where a.name = b.name and
> a.address = b.address and
> a.telephone = b.telephone)
>

The right idea, wrong implementation:

 Update Customer_Table a
 set a.final_price = (select a.price * b.discount from discount_table b
 where a.name = b.name and
 a.address = b.address and
 a.telephone = b.telephone);  

> This query was running for a long time and I killed it. I also suppose
> this query will update ALL rows in the Customer_Table with the same
> value since there is no WHERE clause in the Update.
>
> How can I do this??!!

I've just shown you. :) Oh, and if this isn't homework use a better example or explain WHY you can't use actual table names.

David Fitzjarrell Received on Tue Nov 09 2004 - 09:25:23 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US