简体   繁体   中英

Mysql 3 tables, copy column

I have three mysql table from same database Db1.

Three tables have following columns.

Table 1: Name City Branch

Table 2: Age Address Country

Table 3: No columns.

I want to copy Table1.Name and Table2.Age to Table 3. How can I do it?

This makes little sense if table1 and table2 can not be joined and table 3 doesn't have the 2 columns. If you can join:

insert into table3 (name, age)
select table1.name, table2.age
from table1 join table2 on (table1.columnToLinkFromTable1 = table2.columnToLinkFromTable2)

You could also do it like this, but of course it doesn't make much sense:

insert into table3 (name, age)
    select table1.name, table2.age
    from table1, table2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM