Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy data from a table, into the same table with a different key

Tags:

sql

ingres

I was curious if it was possible to take data from a table, and duplicate it but assign a new primary key

for example, I wish to take data that has a column "question_id" which acts as the unique key for the table, and copy all of the data from the table with that question_id to the same table but with a new question_id.

any thoughts as to if this is possible using SQL?

my database is an ingres database

thanks in advance

like image 810
John Avatar asked Dec 26 '22 17:12

John


1 Answers

Sure, something like this should work:

INSERT INTO YourTable (Question_Id, OtherField,...)
SELECT SomeNewQuestionId, OtherField,...
FROM YourTable
WHERE Question_Id = SomeQuestionId

Just replace SomeQuestionId and SomeNewQuestionId with the appropriate values.

like image 83
sgeddes Avatar answered Dec 28 '22 06:12

sgeddes