LMSouq
database Open

In MySQL, can I copy one row to insert into the same table?

LI
lina
1 month ago
3 views
Problem Description
insert into table select * from table where primarykey=1 I just want to copy one row to insert into the same table (i.e., I want to duplicate an existing row in the table) but I want to do this without having to list all the columns after the "select", because this table has too many columns. But when I do this, I get the error: > Duplicate entry 'xxx' for key 1 I can handle this by creating another table with the same columns as a temporary container for the record I want to copy: create table oldtable_temp like oldtable; insert into oldtable_temp select * from oldtable where key=1; update oldtable_tem set key=2; insert into oldtable select * from oldtable where key=2; Is there a simpler way to solve this?

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base