Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
09-10-2013, 07:47 PM #1
- Join Date
- Feb 2007
- Thanked 1 Time in 1 Post
fetch data from table and write into another
I've got two database tables.. named actual_prices and original_prices.
What I want to do is fetch all prices from within the original_prices table (field: o_price), and add some value to it.. then I want the new calculated price written into the actual_prices table (field: price).
The structure of both tables is:
original_prices: p_id, description, o_price
actual_prices: P_id, description, price
(where P_id is the primary field).
Now let's say I've got this example data within orginal_prices:
1, test product, 20.00
2, another product, 2.00
3, not another test, 11.00
I want to add $5.00 to each product, and store the new price in table actual_prices only. So the example data within actual_prices should look like this:
1, test product, 25.00
2, another product, 7.00
3, not another test, 16.00
I know the sql update statement, but how can I loop through all records within original prices and update the actual_prices ?
09-11-2013, 01:43 AM #2
- Join Date
- Sep 2002
- Saskatoon, Saskatchewan
- Thanked 2,668 Times in 2,637 Posts
There's no update in use, it would be using a INSERT . . . SELECT syntax.
The bigger question is why. Why would you need to replicate the data; are you planning on eliminating the original? Couldn't you simply issue a select and add what you want during selection? You could also create a view to do this automatically for you without replicating the data.PHP Code:
header('HTTP/1.1 420 Enhance Your Calm');