Can you export columns, and then import them to another tbl?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Can you export columns, and then import them to another tbl?

Post by simonmlewis »

I have about 15 fields I need to extract from a DB table.

Rather than my counting how many I need to add, and then copy the exact titles, and field types and characters, can I not just select each field I was to export, and then import that into the current table - but NOT import/export the data within them?

MySQL database.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Can you export columns, and then import them to another

Post by Christopher »

You can SELECT specific fields from one table and INSERT the SELECTed data into another table in one SQL statement.
(#10850)
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Can you export columns, and then import them to another

Post by califdon »

simonmlewis wrote:I have about 15 fields I need to extract from a DB table.

Rather than my counting how many I need to add, and then copy the exact titles, and field types and characters, can I not just select each field I was to export, and then import that into the current table - but NOT import/export the data within them?

MySQL database.
I think you are asking about modifying a table structure to add columns which exist in another table. Are you trying to create a new table with just those columns, or do you want to add those columns to an existing table? If you want to create a new table with exactly the same columns as another table, you could use SHOW CREATE TABLE http://dev.mysql.com/doc/refman/5.1/en/ ... table.html and save the output to a file and then execute that file as SQL, which will create an empty table structure with the same structure as the first one. If you want to add additional columns to an existing table, though, there's no easy way to do that without requiring more fuss and bother than just carefully using ALTER TABLE commands for 15 columns.
Post Reply