Reputation: 344
I have two tables in the same database. With same constraint and same column name. Both tables have primary key with auto-increment and I want insert data directly from one table to the other by using following query.
insert into table_name select * from table_name
all data get inserted into table one but auto-increment is not happening.
in image their is same problem(table in image is created for test)
Upvotes: 2
Views: 67
Reputation: 133370
You can't use * you should use the column name without the id (therwise you insert the selected id and is not performed the autoincrement)
insert into table_name ( col1, col2)
select col1, col2 from table_name;
Upvotes: 3