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 5928505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:17:59+00:00 2026-05-22T14:17:59+00:00

I have two table shere: Cities Region| City Name States ID| State | Region_Key

  • 0

I have two table shere:

Cities
Region| City Name 

States
ID| State | Region_Key

I need to do an update query on the cities table like so i.e set cities.region = statres.id where states.region_key = cities.region

The problem is that the cities database has over 2.7 million records and I tried doing a query like this only for mysql to hang and die out.

update cities c, states c set c.region = s.id where c.region = s.region_key

EDIT ===================

This is the sql I am using but its not working I get an error saying incorrect usage of UPDATE and LIMIT

update cities w, states s 
set w.region_id = s.id, 
w.updated = 1 
where w.region = s.w_code and w.updated = 0
LIMIT 10000
  • 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-05-22T14:18:00+00:00Added an answer on May 22, 2026 at 2:18 pm
    1. Add a nullable bit column [HasBeenUpdated] to the cities table
    2. Add Set c.HasBeenUpdated = 1 to the update clause
    3. Add the following where condition AND c.HasBeenUpdated IS NULL
    4. Add a new WHERE condition AND c.ID in (Select ID from Cities where HasBeenUpdated Is Null Limit 10000). This is needed because you cannot use a Limit statement on a multi-table Update (source). This also presumes that you have an ID column as the PK for cities (if not, then consider adding one). Now the update statement will only process 10,000 rows at a time (and will only process unprocessed rows).

    If you can put this in a loop using your application logic, then this can be used for automation. Change the limit number based on your needs and when it is done, remove the HasBeenUpdated column.

    This should allow you to minimize the impact of the update on the table and database, and allow you to perform it across the whole table in manageable batches.

    Edit: Update step 4 to filter rows to be updated via subquery, since a Limit statement cannot be used on a multi-table Update.

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

Sidebar

Related Questions

I have two table like this table_CN (_id, name, phone, favorite, title) table_EN (_id,
I have two table views, when user clicks one cell of the first, second
I have two table cells, with dynamic content. Table cell one works fine, when
I have two table. One table hold key column and xml column. Other table
I have two table masterTbl and detailTbl which structure is given below... --PRIMARY TABLE
I have two table emptable1(empid,status) emptable2(empid,week) i want to select all the empid whose
i have two table: declare @t1 table (id int) declare @t2 table (id int)
I have two table first is TABLE_SUBJECT and second is TABLE_CHAPTER.Now i want to
i have two table. Records and Villas Records table : ID, VID (Villa ID),
I currently have two models: Product and Service. Both share the same table structure

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.