Update a thousand rows with specific value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MrMob
    New Member
    • Jan 2010
    • 27

    Update a thousand rows with specific value

    I would like to update thousand of Rows with its specific value

    Suppose i have a table XYZ and ABC
    XYZ contains Code,Name,RegDa te And ABC also Contains the same
    but the Value of RegDate of XYZ is Different than that of ABC..
    i want to update XYZ's RegDate Value From the value of RegDate of table ABC
    at once...

    update XYZ set RegDate=
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    How are the two tables related? What's the key that link them together?

    Happy Coding!!!

    ~~ CK

    Comment

    • Delerna
      Recognized Expert Top Contributor
      • Jan 2008
      • 1134

      #3
      One of the simplest ways is
      [code=sql]
      UPDATE xyx
      set datereg=
      (
      select datereg from abc
      where abc.Code=xyz.co de
      and abc.name=xyz.Na me
      )
      [/code]

      but as ck says, you don't indicate which fields are the key

      Comment

      • OraMaster
        New Member
        • Aug 2009
        • 135

        #4
        Small modification in the posted SQL

        UPDATE xyx
        set datereg=
        (
        select datereg from abc
        where abc.Code=xyz.co de
        and abc.name=xyz.Na me
        and abc.datereg <> xyz.datereg
        )

        Comment

        • ck9663
          Recognized Expert Specialist
          • Jun 2007
          • 2878

          #5
          Yet another version :)

          Code:
          UPDATE x
          set datereg = a.datereg
          from XYZ x
          INNER JOIN ABC a on x.code = a.code and a.name = x.name and x.datereg <> a.datereg
          Happy Coding!!!

          ~~ CK

          Comment

          • raveengo
            New Member
            • Mar 2010
            • 4

            #6
            Update a set a.regdate=b.reg date from xyz a,abc b
            where a.code=b.code and a.name=b.name and a.regdate<>b.re gdate

            Comment

            Working...