Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Append content of one table to another

Posted on 2011-09-04
5
Medium Priority
?
356 Views
Last Modified: 2012-05-12
How do I append content of one table to another? They don't identical  structure but they have the same number of fields that I need to merge.

I'm tryng to do it using SSH to the server.
0
Comment
Question by:carloslaso
  • 3
  • 2
5 Comments
 
LVL 80

Expert Comment

by:arnold
ID: 36481668
are the tables within the same database or are you doing it accross databases as well as accross tables?


mysql -u root -p

insert into <newtable> (select column1,column2, column3,... from old table);
0
 

Author Comment

by:carloslaso
ID: 36481684
Is that going to copy the information into the columns? All of the columns on table1 exist on table1 on the other database but has more columns.

I need to copy the information that exist on table1 to table1 on the other database and leave the columns that do not exist on the other database blank.
0
 
LVL 80

Expert Comment

by:arnold
ID: 36481730
http://dev.mysql.com/doc/refman/5.0/en/insert-select.html

Your best bet might be to export the data from one and then import it into the other.

Are you familiar with perl or anyother programming language?

The columns you select will have to match the order and datatype of the one into which you are inserting.
you could specify the column order
insert into database.table (database.column1,......)  (select (1column, 2column, .....) from database2.table where );

0
 

Author Comment

by:carloslaso
ID: 36481766
The order and the datatype match but the table on one database has 24 fields, the table on the other database has 29 fields, the 5 extra fields are at the bottom/end of the table.

No, I'm not familiar with any programming languages :-/
0
 
LVL 80

Accepted Solution

by:
arnold earned 2000 total points
ID: 36481864
Your select statement needs to use the columns in the order in which they exist in the table into which you want the data added.
http://ariejan.net/2008/11/27/export-csv-directly-from-mysql
You can then do the reverse to import
http://dev.mysql.com/doc/refman/5.1/en/load-data.html
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question