Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7761469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:08:37+00:00 2026-06-01T14:08:37+00:00

I’m pretty sure I did this right, but my query has been running for

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:08:39+00:00Added an answer on June 1, 2026 at 2:08 pm

    If I understand your situation correctly, this should be much faster:

    UPDATE `AAA`,`BBB` SET `AAA`.`text`=`BBB`.`text`
    WHERE `AAA`.`id_str`=`BBB`.`id_str`
    

    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_str and BBB.id_str should 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 a CREATE TABLE statement for table AAA? Alternatively, you could try this:

    CREATE TABLE `CCC` LIKE `AAA`;
    INSERT INTO `CCC` SELECT `AAA`.`str_id`,`BBB`.`text` FROM `AAA` JOIN `BBB` ON `AAA`.`id` = `BBB`.`id`;
    

    This doesn’t copy in any data from the old table AAA, though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.