inserting values into mysql table

Posted on 2006-10-28
Last Modified: 2010-08-05
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?

Question by:Steve_Newbie
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 37

Accepted Solution

momi_sabag earned 43 total points
ID: 17825098

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)

LVL 32

Assisted Solution

awking00 earned 41 total points
ID: 17825387
You could create a temporary table with the same structure as the old table, import it, then
insert into new_table

Author Comment

ID: 17826233
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 basically 100 rows of data.

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

New table has added extra fields like the following
Profile Type
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!
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.


Author Comment

ID: 17826518
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) 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?

LVL 37

Expert Comment

ID: 17828135

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)


Assisted Solution

Tayger earned 41 total points
ID: 17829684
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.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
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…

623 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