Results 1 to 7 of 7

Thread: Sql queries

  1. #1
    Join Date
    Aug 2012
    Posts
    32

    Unanswered: Sql queries

    Does anyone know the query to copy column data from one table and put it in another

  2. #2
    Join Date
    Apr 2012
    Posts
    213
    Try something like that:

    Code:
    update MyTable
    set MyColumn = o.MyColumn
    from MyTable as t
    join OtherTable as o on o.ID = t.ID
    Hope this helps.

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by str8uphaitian View Post
    Does anyone know the query to copy column data from one table and put it in another
    why would you want to copy a value from one table to another?
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    Aug 2012
    Posts
    32
    will that query lose my original values? I would like to recreate them without losing my original values.


    I want to copy them because I am running a new application that calls for some but not all of the same data columns. As this is a stand alone app I found it to be more concise and practical to have it draw its data from a seperate table

  5. #5
    Join Date
    Oct 2009
    Location
    221B Baker St.
    Posts
    486
    will that query lose my original values?
    No, the original values will be untouched. Suggest you back up both before experimenting because if you get something crossed, you could update what you do not intend. . .

  6. #6
    Join Date
    Aug 2012
    Posts
    32
    I finally got it. Here was the code that ended up working

    UPDATE table1 SET table1.column=table2.somecolumn
    FROM table1, table2
    WHERE table1.anothercolumn = table2.yetanothercolumn;

  7. #7
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Please use JOIN syntax:

    UPDATE table1 SET table1.column=table2.somecolumn
    FROM table1
    inner join table2 on table1.anothercolumn = table2.yetanothercolumn;
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

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