inserting values into mysql table

Probably basic, but I am a novice in mysql....just able to manipulate data in phpmyadmin and run rudimentary queries.

I have two tables in two different mysql databases.
Want to move the older table values into the new one.
The new table has more field rows (89) than the old one that is populated with values (72).
Both tables have the same field names, its is just that there are new ones added to the newer version of the dbase.

Is there a way to import by matching the field names or something like that?  Or how do I enter null values or deault values into the old table's data so it matches up with the number of fields in the new table? Or basically what is the best way to match these up so I can import the data to the new table?

Thanks.
Steve_NewbieAsked:
Who is Participating?
 
momi_sabagConnect With a Mentor Commented:
hi

if the table don't have many rows (that is only couple of thousends)
you can define in one of the databases a connected table (it' s a reference to a table at a remote mysql server)
and then you can just do insert as select from the old table to the new table,
while you perform the select , you can add the default values you wish to enter into the new tables,
if your columns are in the same order , all you will have to do is :

insert into new_table
select *, add_values_here
from old_table

if your table has many rows, you might consider doing this inside a procedure with some commit logic, or try to do it using export from the old table, aNd import to the new one
if you choose the export import approch, then you will have to define default values for all the new columns in the new table (when you create it or by using alter table)

momi
0
 
awking00Connect With a Mentor Commented:
You could create a temporary table with the same structure as the old table, import it, then
insert into new_table
(col1
,col2
...
,col72
,col73
...
,col89)
select
 col1
,col2
...
,col72
,null
...
,null)
0
 
Steve_NewbieAuthor Commented:
I'm sort of following both of the answers which seem similar, but need it a little more specific to my field nomenclature and dumbed-down even more......just think of me as Homer Simpson I guess..

This is  member profiles table by the way, and there are about 100 of them.....so basically 100 rows of data.

Specifically I have the old table showing something like this:
ID
Name
Country
ZIP
Date of Birth  etc. etc. etc.

New table has added extra fields like the following
ID
Name
Profile Type
Country
State
Zip
Date of Birth etc. etc. etc.

So, for this abbreviated example, what language or queries do I use to cover the extra fields of "Profile Type" and "State" in the new table?  The current/old profiles table has not have values assigned to "Profile Type" or "State" .

Is there a simple way, using the example above to use the intrinsic functions of "Import" "Export" or "Operations" within phpmyadmin?  If not, do I have to use different software to create tables for export, import etc., again specifically using the abbreviated table fields examples noted above?  I have SQLyog Pro but have not used it much.  


Thanks much!
0
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
Steve_NewbieAuthor Commented:
I have now purchased SQLyog Eneterprise to be able to do more advanaced synch operations, especially since I need a bonehead easy way to do this....
Anyway, even using that, when I specifically select  ONLY one field to synch data (e.g. ID field which exists in both tables).....it comes back with an error sawing that the field count is not equal between the tables.  What am I missing here?  I selected only ONE field to synch...why should it care about the other fields in the table in this case?

Thanks.
0
 
momi_sabagCommented:
hi

i'm not familiar with SQLyog but maybe when you select sync by field, then the field you choose is the field used to make the comparison (maybe that field defines the primary key for the 2 tables)

momi
0
 
TaygerConnect With a Mentor Commented:
Take care of inserting/overriding fields if they

a) have a primary key or foreign key on it
b) have "enum" (automatic) counter on it

To a)
Disable/delete them before inserting

To b)
MySQL will set a ID into those automatically when you do a insert. Ignore those fields on inserting (exclude them from export/import). Just let MySQL do the job on those.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.