This one is braking my head . Moving old articles rating for client from old DB to new DB where the only reference between them is first word which is separated by dash in article title. I am able to pull the info I need by using SELECT but I cant figure out how to use the result to update the new table
table that needs to be updated
UPDATE
newDB.newtable.rating
SET newDB.newtable.rating.rating_count = oldvotes
the select that gives me the info on oldvotes
SELECT
oldvotes.votes AS oldvotes, old.title AS oldtitle,newtable.news_items.title as newtitle,newtable.news_items.id AS newID
FROM
oldDB.news_items AS old
INNER JOIN
oldDB.news_items.rating_count AS oldvotes
ON
oldvotes.article_id = old.id
INNER JOIN
newDB.newtable.news_items
ON
newDB.newtable.news_items.title
LIKE CONCAT
( '%', SUBSTRING_INDEX( old.title, '- ', 1 ) , '%' )
any help is appreciated!
If I understand correctly, you have in old.title something like thisisauniquekey-september-2012, and in news_items.title the value ‘thisisauniquekey-somethingelse’.
You could select a key (a faster key than the title) and the oldvotes into a temporary table, say,
oldratings, using the same query you run now:Then you can run the update using
oldratings: