1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

In same DB > How to copy column from table1 to table2

Discussion in 'General PHP and MySQL Discussions' started by sadiq6210, Aug 26, 2015.

  1. sadiq6210

    sadiq6210 Active Member

    How can I copy (column1 in table1) to (column2 in table2)?

    Note that:
    1- Both tables are in same database.
    2- There is data in both column, so I want to replace all (column2) exist data with (column1) data.

    I tried many queries but nothing is working !
  2. Snog

    Snog Well-Known Member

    I believe something this should work. You may also need to include the main ID column from both tables to keep them in sync...

    UPDATE Table2 AS table2 SET table2.column2 = (SELECT column1 FROM Table1 AS table1 WHERE table1.mainIDcolumn = table2.mainIDcolumn)

    Untested, so I don't know for sure if it will work. ;)
    Last edited: Aug 26, 2015
    sadiq6210 likes this.

Share This Page