Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. update in the same table

update in the same table

Scheduled Pinned Locked Moved Database
databasequestionannouncement
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Goodway
    wrote on last edited by
    #1

    hi everyone, I want to update a row in a table in SQL with values from another row in the same table, i wrote this: UPDATE Income_Codes IC SET IC.DateLeave = IC1.DateLeave FROM Income_Codes IC1 WHERE IC.Cm = 420 AND IC1.Cm = 911 but it didn't work. I tried this: update Income_Codes set DateLeave = (select DateLeave from Income_Codes where Cm = 911) where Cm = 420 it worked, but if i have to update 20 fields, i have to write 20 selects, any other solution? Thanks

    S 1 Reply Last reply
    0
    • G Goodway

      hi everyone, I want to update a row in a table in SQL with values from another row in the same table, i wrote this: UPDATE Income_Codes IC SET IC.DateLeave = IC1.DateLeave FROM Income_Codes IC1 WHERE IC.Cm = 420 AND IC1.Cm = 911 but it didn't work. I tried this: update Income_Codes set DateLeave = (select DateLeave from Income_Codes where Cm = 911) where Cm = 420 it worked, but if i have to update 20 fields, i have to write 20 selects, any other solution? Thanks

      S Offline
      S Offline
      softty
      wrote on last edited by
      #2

      delete the first row, and insert second row just changing the primary key love2code

      A 1 Reply Last reply
      0
      • S softty

        delete the first row, and insert second row just changing the primary key love2code

        A Offline
        A Offline
        anandss
        wrote on last edited by
        #3

        If you want both rows, then use the following UPDATE table SET (col1, col2, col3,..., col20) = (SELECT col1, col2, col3,..., col20 FROM table WHERE ) WHERE ;

        G 1 Reply Last reply
        0
        • A anandss

          If you want both rows, then use the following UPDATE table SET (col1, col2, col3,..., col20) = (SELECT col1, col2, col3,..., col20 FROM table WHERE ) WHERE ;

          G Offline
          G Offline
          Goodway
          wrote on last edited by
          #4

          I tried it, but it gives an error, any other solutions. Thanks anyway.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups