Duplicating records while making some changes

I have the following table with the following fields:
jexp_vikappointments_emp_worktime
=>id (primary key)
=>id_employee
=>id_service
=>day
=>fromts
=>endts
=>ts
=>closed

I am wanting to make a duplicate of all records where id_employee equals 1 but at the same time update id_employee for the new record to 2.

I don’t mind doing this in two steps if its easier i.e. make a straight duplicate and then run a second query which updates the id_employee for all id (primary key) above a certain number.

I tried playing with the following command:

insert into `jexp_vikappointments_emp_worktime` (SELECT id_service,day,fromts,endts,ts,closed FROM `jexp_vikappointments_emp_worktime` where id_employee="1") 

But I have two issues:
1 I kept getting duplicate ID errors
2 For the above command I am not sure how to add the updated id_employee

INSERT INTO jexp_vikappointments_emp_worktime ( id_employee , id_service , day , fromts , endts , ts , closed ) SELECT 2 -- new id_employee , id_service , day , fromts , endts , ts , closed FROM jexp_vikappointments_emp_worktime WHERE id_employee = 1

1 Like

Perfect, thanks

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.