How to transfer data from one table to another with different structure

Discussion in 'MySQL' started by Junije, Aug 21, 2010.

  1. #1
    So, I have two MySQL tables "new_table" and "old_table", what I would like to know is how can I transfer all the data I have in my old table to my new table :(

    The two tables share the same structure up to first 15 columns, but the new table also has additional 10 more columns which the old table doesnt have.

    Is there any way I can do this without manually copying the data, which I have been doing for all this time? :confused:
     
    Junije, Aug 21, 2010 IP
  2. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Use INSERT INTO....SELECT e.g.

    INSERT INTO new_table (column1, column2, column3)
    SELECT col1, col2, col3 FROM old_table
    Code (markup):
     
    mwasif, Aug 21, 2010 IP
    Junije likes this.
  3. Junije

    Junije Well-Known Member

    Messages:
    136
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #3
    Great, thanks mwasif! Rep +
     
    Junije, Aug 21, 2010 IP
  4. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #4
    You are welcome
     
    mwasif, Aug 21, 2010 IP