Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2005
    Posts
    71

    Unanswered: How to update a field in row2 with a value from row1 and so on...

    table:
    f1 integer PK
    f2 integer
    f3 integer

    row1
    1, 0, 3
    row2
    2, 0, 4
    row3
    3, 0, 5

    what i would like to know how to do is how do i get the f3 value from row1 into the f2 value of row2 and then copy the f3 value of row2 into f2 value of row3?
    new output:
    row1
    1,0,3
    row2
    2,3,4
    row3
    3,4,5

  2. #2
    Join Date
    Feb 2003
    Location
    India
    Posts
    216
    the updation logic is simple provided that a relation (self join) can be made. assuming that the PK field f1 is in serial with no gaps ....

    Code:
    update table1 set f2=t2.f3 from table1, table1 as t2 where table1.f1 = t2.f1+1

Posting Permissions

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