Phil
Phil

Reputation: 1849

Is this a good way of copying data from one table to another?

I have two tables, links1 and links2. Links1 one has several million rows with the following columns: ID, URL, UTitle and UDesc. The URL column holds urls from around the web, and the UTitle and UDesc columns are empty.

Links2 also has several million rows with the following columns: ID, URL, title and description. The URL column has urls, but most of them are different ones than the ones in links1. The title and description columns are filled with the title and meta:description for the url in each row. I'm now trying to compare the two tables, and whnever one of the urls in link2 corresponds to a url in links1, I want to copy the data in title and description (in links2) to UTitle and UDesc (in links1).

I'm still new at Mysql, so I'm not sure the following is the fastest/best way to do this. I'd appreciate your input if there is a better/faster way.

UPDATE links1
INNER JOIN links2 ON (URL.value = URL.value)
SET links1.UTitle = links2.title, links1.UDesc = links2.description

Thanks!

Upvotes: 1

Views: 68

Answers (1)

Hamlet Hakobyan
Hamlet Hakobyan

Reputation: 33381

It is faster way with one query, but you have a mistake in your query. Here is the corrected version:

UPDATE links1
INNER JOIN links2 ON (links1.URL = links2.URL)
SET links1.UTitle = links2.title, links1.UDesc = links2.description

Upvotes: 2

Related Questions