Move SQL data from one table to another

后端 未结 13 2897
梦如初夏
梦如初夏 2020-11-29 20:34

I was wondering if it is possible to move all rows of data from one table to another, that match a certain query?

For example, I need to move all table rows from Tab

13条回答
  •  悲哀的现实
    2020-11-29 21:21

    You should be able to with a subquery in the INSERT statement.

    INSERT INTO table1(column1, column2) SELECT column1, column2 FROM table2 WHERE ...;
    

    followed by deleting from table1.

    Remember to run it as a single transaction so that if anything goes wrong you can roll the entire operation back.

提交回复
热议问题