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

  • Home
  • SEARCH
  • 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 9033099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:08:38+00:00 2026-06-16T08:08:38+00:00

I have a strange problem. I got some data for cities, regions and countries

  • 0

I have a strange problem. I got some data for cities, regions and countries in CSV format and imported them into MySQL tables.

I have 3 tables and their fields

1. City    : id, name, country_code, region_number
2. Region  : region_number, country_code, name
3. Country : country_code, name

Now things get a little complicated, as I added an auto-generated id column to the region table, so the region x for country y would be unique.

The thing is: Now i am trying to update city field region_number to hold this unique value (the new id column in region) so I can have relations city->region.

The relation region->country or country->region is OK.

Is it possible to write an update query that would update city region_code (or fill some new column, eg. region_id) with correct values?

If not an query, what could I use to get the correct values into the cities table?

I have arround 3 million records!

  • 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-16T08:08:40+00:00Added an answer on June 16, 2026 at 8:08 am

    If I understant correctly, I think you are looking for something like this:

    UPDATE
      City inner join Region
      on City.country_code = Region.country_code
         and City.region_number = Region.region_number
    SET
      City.new_column = Region.id
    

    However, since there’s a relation already between City and Region, I am not sure this is the right thing to do, since it will make the table not normalized.

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

Sidebar

Related Questions

I have got problem while inserting some data in polish language(characters like ąćęłóżź) into
I've got a strange problem here. Assume that I have a class with some
I have got a strange problem about in_array recently which I cannot understand. e.g.
I got a strange problem. I have a tabcontrol and 3 tabs. On every
I have strange problem with receiving data from socket. On client im using air
I have a strange problem with integrating a ViewController into another ViewController . i
I've got a strange problem here. I have a class that I'll call MainView
has any one using Spring MVC with Jquery! i have got a strange problem
I have encountered a very strange problem when trying to insert multiple Strings into
got a problem with one to one relations I have some Matches and i

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.