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

This is my first question, so please be kind if this question has already been asked. And my English is not very good;) I have a XAMPP MySQL server and you want to make a statement INSERT SELECT, but if I run the statement, I will 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 do not want to rewrite the table "amt", it should be added only to the table fach.

I want to add this table image of the table "fach" to this. table image "amt"

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

+4
source share
2 answers

You need to set your index index to automatically increase:

ALTER TABLE `amt` MODIFY COLUMN `id_amt` INT auto_increment
+6
source
INSERT INTO amt (id_amt, Bezeichnung)
SELECT (select coalesce(max(id_amt), 0) + 1 from amt), Bezeichnung
FROM fach
0
source

Source: https://habr.com/ru/post/1541876/


All Articles