Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy tables with different column name MySQL

I need to copy all rows from table1 matching specific columns into table2 with different columns name. For example:

  • table1 name = oldAddressBook , table1's columns name = Name,Surname,Number
  • table2 name = newAddressBook , table2's columns name = newName,newSurname,Phone

Data in columns "Name,Surname,Number" in "oldAddressBook" must fill respectively "newName,newSurname,Phone" in "newAddressBook". "oldAddressBook" and "newAddressBook" contain also other columns.

like image 894
user626415 Avatar asked Dec 28 '22 21:12

user626415


1 Answers

INSERT INTO newAddressBook (newName, newSurname, Phone)
SELECT name, surname, number
FROM oldAddressBook
like image 91
a_horse_with_no_name Avatar answered Dec 30 '22 12:12

a_horse_with_no_name