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?
Check following query
this query is enough to update main table