Finglish
Finglish

Reputation: 9956

sql how to make multiple copies of a row in the same table

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

Answers (2)

Fabian Bigler
Fabian Bigler

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

Veer Shrivastav
Veer Shrivastav

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

Related Questions