I have two mysql table
Table 1
id email other fields
Table 2
id email other fields
where id for table1 is auto increment mysql column. and in table 2 id is only primary key not NULL .
some how the id for table 2 had gone wrong.
Now both tables are having some records and I want to make id in table 2 same as table 1.
let’s take an example
Table 1 have
1 a@a.com
2 b@b.com
Table 2 have
1 b@b.com
2 a@a.com
if I fire query
update
table2
set
id=(select id from table 1 where email="a@a.com")
where
email = "a@a.com"
I will get error because table 2 is already having id value of 2.
now how can I solve this problem ?
I want id of table2 same as table1 based on email.
How about this :