Log in

View Full Version : Joining same table & update query



kaushal
03-06-2012, 10:38 AM
Demo Table: orders
orderid amount disc_amt actual_amount
1000 500 100 500
2000 600 200 600
3000 400 200 400

Now I am having a requirement that to update actual_amount of each order that is subtracted by disc_amt.

I want to know what should be the update query?

Please Help.

Thanks
Kaushal.

james438
03-06-2012, 11:24 AM
If I am understanding you correctly you want to update your orders table so that the actual_amout reads actual_amount - disc_amt.

Try this:


UPDATE orders SET actual_amount=(actual_amount - disc_amt)

This will update all of the rows in your orders table changing the actual_amount to actual_amount minus disc_amt.

kaushal
03-06-2012, 12:15 PM
Wow James what a magic...
You are awesome.
Thank you for helping me.
Thanks again.