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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:35:58+00:00 2026-05-25T19:35:58+00:00

I have a user table with following fields id int name varchar dob date/time

  • 0

I have a user table with following fields

id           int
name         varchar
dob          date/time

Now, I have another table called user_map table, with 2 fields

oldid        int
newid        int

user_map table is used for storing user id mapping, field ‘oldid’ is user’s old id (which is current user id from user table), and ‘newid’ is user id going to be assigned

I need a single update query, which can update user id for all users in user table

How should it work? Well, for each id in user table, there will be only 1 record matching in user_map table.

id from user table matches oldid from user_map table, and it should be replaced by newid

For example (ignore dob field please)

user table

       id                   name                     dob
        1                    aaa                     0000-00-00 00:00:00
        2                    bbb                     0000-00-00 00:00:00
        3                    ccc                     0000-00-00 00:00:00

user_map table

      oldid       newid
        1           6   
        2           7   
        3           8   

After query, user table should look like

user table

       id                   name                     dob
        6                    aaa                     0000-00-00 00:00:00
        7                    bbb                     0000-00-00 00:00:00
        8                    ccc                     0000-00-00 00:00:00

how can I achieve this? is it possible in 1 query only?

  • 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-25T19:35:59+00:00Added an answer on May 25, 2026 at 7:35 pm

    Check following query

    update `user table` a, `user_map` b  set a.id=b.newid where a.id=b.oldid
    

    this query is enough to update main table

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

Sidebar

Related Questions

I have one table called: Transaction. This table has the following fields: (ID,ProductName,Amount,Date) placed
Hi I have a mysql table having the following fields A INT, B INT,
I have the following MySQL table fields: description1 , description2 , description3 : Varchar(500)
I have a table called Follow , with three fields: Id (autoincrement int), UserId
I have a following table using MVC that shows number of items the user
I have following situation: I have loged user, standard authentication with DB table $authAdapter
In database I have Contacts table: ContactID (int) FirstName (varchar) LastName (varchar) ... XmlFields
I have a SQL table (Trade Mapping) with the following columns: BTF_TRADE_MAPPING_KEY int BTF_SYSTEM_CODE
I have a table tbluser with 2 fields: userid = integer (autoincrement) user =
I have an SQL table with basically the following structure: PK (int, primary key),

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.