I have a MySQL table called employees. There’s another table called shifts that is tied to employees by the employeeId column and a one-to-many relationship. I want to clone an employee and his shifts using INSERT – so the employee row is cloned, and the shifts are all cloned and have the new auto-incrementing primary key that was generated for the new employee. Is this possible in one query?
I have a MySQL table called employees . There’s another table called shifts that
Share
Yes but not with a single insert.
You’d have one INSERT to do the employee, then a second INSERT with a sub-SELECT to SELECT all of the shift data.
Here are some examples