Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update with subquery

Status
Not open for further replies.

mmetze

Programmer
Oct 2, 2001
45
0
0
US
I am trying to update all rows in a table based upon values found in another table. Below is an example of what I am trying to accomplish...

UPDATE table1 t1
SET t1.column1 =
SUM(
SELECT t2.column1
FROM table2 t2
WHERE t1.column2 = t2.column2
AND t1.column3 = t2.column3
AND t2.column4 = 'GROUP')

I don't believe that I can reference the table being updated as above within my subselect, can I?
 
Hi,
Please find herewith attached solution.

update table1 set t1.column = (select sum(t2.column1)
FROM table2 t2
WHERE
t1.column2= t2.column2
AND t1.column3 = t2.column3
AND t2.column4 = 'GROUP');


Thanks,
Ravi.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top