I’m pretty sure I did this right, but my query has been running for half an hour now on a MySQL database on a regular laptop. The “tweets” table is only 1 million records big.
What do I want? Consider table “AAA” (left) and “BBB” (right)
id_str text id_str text
------------ -------------------
13 13 foo bar baz
14 14 foobar
13 foo bar baz
17 foobaz
I want to fill the “text” column of table A with the text from table B:
UPDATE AAA
SET `text` = (
SELECT `text` AS `text`
FROM BBB
WHERE id_str = AAA.id_str
LIMIT 1
)
So that table AAA would look like
id_str text
-------------------
13 foo bar baz
14 foobar
However, as said, this query is running far too long. Did I make a mistake in its syntax?
If I understand your situation correctly, this should be much faster:
You should only have to run this query once. It may still take a few minutes, but doing it this way (with a JOIN) is still probably going to be a lot faster than running 1 million separate queries.
AAA.id_strandBBB.id_strshould both be indexed and preferably of the same data type, e.g. both should be int(11). This allows MySQL to evaluate the equality relationship between them with maximum efficiency.EDIT: As I said, the query outlined above may still take some time, depending on your system configuration and your hardware (the operation could be disk-bound, i.e. limited by the speed of your hard disk). It could also be because MySQL is having to update indexes in table
AAA– could you show us aCREATE TABLEstatement for tableAAA? Alternatively, you could try this:This doesn’t copy in any data from the old table
AAA, though.