Data Migration In Mysql Table

Update migrated table id to related tables

I have three 5 tables.








I have relations as below

  • user has many events

  • ser has many tasks

  • user has many agreements

  • I have do below changes.

First Change - Done

Now I have migrated user data into person table using below query.(This works)

INSERT INTO person (person_type,company_id,first_name,last_name,password,email,image,is_delete) 

    SELECT "user" as person_type,1 as company_id,first_name,last_name,password,email,image,is_delete

    FROM `user`

Second Change

After migrating user data into person table, i want to update new person_id of person table into event,task,agreement with existing user.

How to do it? Please help me.

Thanks in Advance.

I have found the solution.

Using join in update query.

UPDATE event,user,person 

	SET event.person_id = person.person_id

	WHERE event.person_id = user.user_id and =