MRA
MRA

Reputation: 277

How do I copy one colum to another new tables

Example my table structure

current_db

ID email           name  address    phone
---------------------------------------------
1  [email protected] John  My Address  123456789
2  [email protected] Peter My Address  123456721

new_db

ID email column1  column2 column3  column4
------------------------------------------

How do I copy only email address from current_db to new_db.

Upvotes: 0

Views: 55

Answers (2)

DRapp
DRapp

Reputation: 48139

Think I mis-understood... early for me. You mentioned from one database to another, not table to table.

If the tables were actually kept in separate "databases", such as rebuilding, or porting to a new database from an old and you were restructuring tables.... You would have to prefocus to the new database and create your table from an insert of the column desired from database.table from another.

use New_db
create table x select email from Other_Db.YourTable

However, from re-reading and seeing the other answer, that's probably closer to what you want

insert into OneTable ( columnX, columnY, columnZ ) values select x, y, z from OtherTable where...

Upvotes: 1

knittl
knittl

Reputation: 265154

Use the INSERT … SELECT syntax:

INSERT INTO `new_db` ( `email` )
SELECT `email` FROM `current_db`

Upvotes: 1

Related Questions