4

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

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
SFFan123
  • 61
  • 1
  • 6

2 Answers2

6

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

ALTER TABLE `amt` MODIFY COLUMN `id_amt` INT auto_increment
Uriil
  • 11,948
  • 11
  • 47
  • 68
0
INSERT INTO amt (id_amt, Bezeichnung)
SELECT (select coalesce(max(id_amt), 0) + 1 from amt), Bezeichnung
FROM fach
Rooney
  • 26
  • 2
  • No sorry, this statement deosn't work. #1062 - Duplicate entry 'X' for key 'PRIMARY' X = 15+numbersOfTrys – SFFan123 May 24 '14 at 12:57