Search code examples
mysqlsqlselectinsert-into

INSERT SELECT, Duplicate entry '0' for key 'PRIMARY' without overwriting other table


This is my first question so please be kind if this question is already been asked. And my english is not very well ;) I have a XAMPP MySQL-server and want to make a INSERT SELECT statement, but if I run the statement i get this error: #1062 - Duplicate entry '0' for key 'PRIMARY' Here is my SQL-statement: INSERT INTO amt (Bezeichnung) SELECT Bezeichnung FROM fach

But I don't want to overwrite the table "amt", it should only be append at the table fach.

I want to add this table picture of table "fach" to this. picture of table "amt"

"Bezeichnung" = GER, description; "amt" = GER, function


Solution

  • You need to set your ID column to be auto increment:

    ALTER TABLE `amt` MODIFY COLUMN `id_amt` INT auto_increment