Sql to insert data into colum based on another column value

INSERT INTO tableX (ColumnPk,column1, column2)
VALUES((SELECT  max(columnPk) from tableX)+1, 'Column1 value', 'Column2 Value')

I tried this, but getting error 1093: you cannot specify the target table 'organizationmanagement' for updating in the FROM clause

+3
source share
1 answer

You do not use VALUESwhen using the result SELECT:

INSERT INTO tableX (ColumnPk, column1, column2)
SELECT max(columnPk)+1, 'Column value', 'Column2 value';

Is there a reason why you did not configure it columnPkas an auto-increment column, so it will do it automatically?

+1
source

All Articles