Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
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.7k 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.

Browse Categories

...