Mysql – Two diferent time thesql databases with same uniqueid autoincrement values need to be merged

insertMySQLquery

I am a beginner at SQL, so I will try to ask for help.

As I have a database where is primary key where values are incremented by +1.
And I made this database backup, and have another database same as that one.
Where unique id also auto increments. But now I need to insert the old database into an old one.
The only way to separate from old to new is the DateTime colon where is the date of each database value.

Best Answer

INSERT INTO new_table
    (id, ...)
    SELECT id + 1000, ...
        FROM old_table;

This assumes the target table has ids no larger than 1000; adjust if needed.