learner
learner

Reputation: 344

Data from one table to another in MySQL

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)

enter image description here

Upvotes: 2

Views: 67

Answers (1)

ScaisEdge
ScaisEdge

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

Related Questions