Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> A question about UPDATE. How smart is oracle
Hi !
A quick question from a danish oracle newbie.
I have 2 tables, and i want to update a field in table t1 with the sum of a field in table t2.
The tables are BIG, so therefore i want the statement to be a effective as posible.
I have made 2 statements, shown below. Which one should i use ?
Statement 1:
UPDATE table1 t1 SET t1.TotalQty = (Select sum(t2.Qty)FROM table2 t2
WHERE t1.itemnumber=t2.itemnumber)
or
Statement 2:
UPDATE table1 t1 SET t1.TotalQty = (Select sum(t2.Qty)FROM table2 t2
WHERE t1.itemnumber=t2.itemnumber) WHERE t1.TotalQty != (Select
sum(t2.Qty)FROM table2 t2 WHERE t1.itemnumber=t2.itemnumber)
Will oracle make unnessesary updates if i use statement 1, or will it actually jus update the rows, were t1.TotalQty != (Select sum(t2.Qty)FROM table2 t2 WHERE t1.itemnumber=t2.itemnumber)
Thanks in advance, for any help given to me.
Regards, Ole
By the way - if anyone nows some good webpages, with sql-tutorials, please let me know... Received on Mon May 16 2005 - 14:04:22 CDT