Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2004
    Posts
    1

    Unanswered: 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

  2. #2
    Join Date
    Mar 2004
    Posts
    80
    update 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>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •