INSERT INTO courses1 (sys_id,name, location)
WHERE sys_id= $sysid
Integrity constraint violation: 1062 Duplicate entry '1' for key 'PRIMARY'' in
INSERT IGNORE INTO
This question is a perfect example that demonstrates the fact that to give an answer, one have to understand the context of the question, not just write an automated post triggered by some keyword in the question.
If you want a history table, it have to have a different structure from the main table. At least it should have a non-unique key for the id from the main table.
So, make a history table of the same structure, but add a
main_id field. That gives you a structure like
id manin_id name location
Then, to add a record into a history table,
INSERT INTO courses_history SELECT NULL, * FROM courses WHERE sys_id=?
you may want also to add an index (non-unique) for the
This way it will allow to store multiple "replicas" of the same row from the main table.
To get the last replica, you need a query like this:
SELECT * FROM courses_history WHERE sys_id=? ORDER BY id desc