Sunday, February 19, 2012

Help with update

I want to do something like this:
update a set a.col2= max(b.col2) from TableA a,TableB b where a.col1=b.col2

it says aggregate may not appear in the set list of an update statement.
Is using a cursor only solution to this or I am doing something wrong and it can be written in a simple update statment?
any help welcome.
thankyou.
Jyaa :oupdate a set a.col2= max(b.col2) from TableA a,TableB b where a.col1=b.col2

u can do it with update statement.
instead of using TableB use an intermediate table with col2 and max(col2) columns.
<code>
update a set a.col2= b.maxcol2 from TableA a,(select col2,max(col2) as maxcol2 from TableB group by col2) as b where a.col1=b.col2
</code>

No comments:

Post a Comment