0 votes
1 view
in SQL by (20.3k points)

I have a large number of rows that I would like to copy, but I need to change one field. I can select the rows that I want to copy:

select * from Table where Event_ID = "120"

Now I want to copy all those rows and create new rows while setting the Event_ID to 155. How can I accomplish this?

1 Answer

0 votes
by (40.3k points)

You can try using the below code: 

INSERT INTO Table

          ( Event_ID

          , col2

           ...

          )

     SELECT "155"

          , col2

           ...

      FROM Table WHERE Event_ID = "120"

In the above code, the col2, and other columns represent the remaining columns (the ones other than Event_ID) in the table.

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...