How do I merge two tables in MySQL? I've looked at several other posts on this topic but they don't go into enough detail for me.
I'm a novice MySQL user, so bear with me I have a primary table and a temp table that look like this:
CREATE TABLE
temp_import
(id
int(11) NOT NULL auto_increment,
Name
varchar(255) default NULL,
MerchantID
int(11) default NULL,
SKU
varchar(255) default NULL,
PRIMARY KEY (id
) ) ENGINE=MyISAM AUTO_INCREMENT=765811 DEFAULT CHARSET=utf8;
I'm inserting data into the temp table like this:
LOAD DATA LOCAL INFILE \'29762.txt\' REPLACE INTO TABLE temp_import FIELDS TERMINATED BY \'|\' OPTIONALLY ENCLOSED BY \'"\' LINES TERMINATED BY \'\n\' (Name, MerchantID, SKU);
The table format of each table is the same, but the data changes over time. Some items the data chances but the SKU remains constant. Some items will no longer be offered and need to be removed from the database.
example:
Current Database Table:
1, dog, 101, dog101
2, cat, 101, cat101
3, chicken, 102, chicken100
4, chicken food, 102, chicken101
New Database Table:
1, dog, 101, dog101
2, cat, 102, cat101
3, chicken, 102, chicken100
5, Frog, 103, frog101
Final Result Should be
1, dog, 101, dog101
2, cat, 102, cat101
3, chicken, 102, chicken100
5, Frog, 103, frog101
Deleted chickenfood, added Frog, updated cat.
Also this needs to be as efficient as possible. I'll be working with some huge files. And it can be MySQL only code.
http://www.xaprb.com/blog/2006/02/21/flexible-insert-and-update-in-mysql/ I've looked over this but it's over my head, when I try to do this it doesn't work...