Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to Transfer data from a table to another table with more columns?

I have one table with 20 columns that I need to transfer to a new table with 25 columns. I was wonder if there is any possibility to do so? I will much appreciate any source that will lead me to solution. Thank you so much for your time and help.

I will make a short example below:

table.1 includes, let's say 4 columns in this order: t1.First_name, t1.last_name, t1.Phone_number, t1.Address

and I want to transfer this data to Table.2 that includes these columns in this order: t2.First_name, t2.Last_name, t2.Gender, t2.Phone_number, t2.Phone_type, t2.Address

like image 658
Pedram Salamati Avatar asked Sep 05 '25 03:09

Pedram Salamati


1 Answers

INSERT INTO table2 ( First_name, Last_name, Gender, Phone_number, Phone_type, Address)
SELECT  First_name, last_name, 'M', Phone_number, 'cell', Address
FROM    table1

For columns that don't exist in source table you need to provide default values or NULL, and update them later.

like image 146
z m Avatar answered Sep 07 '25 21:09

z m