Akosha
Akosha

Reputation: 471

first duplicate and then change ID of duplicated data in mysql

I have records in table that I need to duplicate for some ID and to add different ID to that rows. Is it possible to be done with one query or I need to select first save that array of rows and then do update and insert?

The insert query for one row of table is:

insert into anag_competenze_medico (id_global_key, id_competenze_medico, id_anagrafica, valore_fisso, valore_percentuale, valore_fisso1, valore_percentuale1, valore_fisso2, valore_percentuale2, id_prestazione, id_user_invalidation, date_invalidation, id_user_changes, date_changes) values (-1, -1, -1, 0.00, 35.00, 0.00, 0.00, 0.00, 0.00, -1, -1, null, 1, '2011-07-19 00:00:00');

From it you can see structure of table.

In general I have doctors and their competences. When another doctor came to work on same possition I want just to run query and copy all competences for another doctor. So in general I need to duplicate that row but with ID of new doctor.

Upvotes: 0

Views: 230

Answers (1)

Samson
Samson

Reputation: 2821

You can try:

 INSERT INTO anag_competenze_medico (id_global_key, ...)
    (SELECT 'newID',....
    FROM anag_competenze_medico 
    WHERE id_global_key= 'oldID')

This copies the competencies of doctor with oldID to a new doctor (newID)

Upvotes: 2

Related Questions