Okay, here goes!
INSERT INTO retailers
(retailername, retailerdesc, retailerwebsite, retailerurl, active)
SELECT
datasource_retailername,
datasource_retailerdesc,
datasource_retailerwebsite,
datasource_retailertrackurl,
1
FROM
datasources_retailers_idx AS i
LEFT OUTER JOIN
retailers AS r
ON
r.retailername NOT REGEXP REPLACE(i.datasource_retailername, ' ','.+')
UPDATE datasources_retailers_idx SET idretailers=last_insert_id();
Here's what I'm trying to do:
Select from old table
check if there is a matching retailer in the new table
If not, insert retailers details into new table
Update a reference column in the old table with the INSERTID primary key value of that row from the new table
The problem is that - as it should - the 'last_insert_id' is the VERY LAST row entered into the database. - So every row in the old table is updated with the LAST inserted ID.
I am trying to avoid PHP completely and do it totally in mysql - I can do it in php, but it takes 9 hours to complete.
Someone please help!!!!