Reputation: 9956
I need to make multiple copies of the same row in a mysql database table.
The only column that changes is the "ID" which is auto incremented.
Is it possible to do this with an sql query?
Upvotes: 3
Views: 1919
Reputation: 10895
Yes, no problem.
Use the Insert Select and select all columns except your ID.
Example:
INSERT INTO tbl_temp2 (fld_id)
SELECT tbl_temp1.fld_order_id
FROM tbl_temp1 WHERE tbl_temp1.fld_order_id = 1;
Upvotes: 1
Reputation: 5496
yes, it is possible.
say for example you have following database..
+++++++++++++++++++++++++
+ id +++ Name +++ Dept ++
+++++++++++++++++++++++++
+ 1 +++ Albert ++ IT ++
++++++++++++++++++++++++++
So use this query..
insert into table1(Name, Dept) as select name, dept, from table1 where id =1;
Upvotes: 3