Move SQL data from one table to another

后端 未结 13 2891
梦如初夏
梦如初夏 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:17

    If the two tables use the same ID or have a common UNIQUE key:

    1) Insert the selected record in table 2

    INSERT INTO table2 SELECT * FROM table1 WHERE (conditions)
    

    2) delete the selected record from table1 if presents in table2

    DELETE FROM table1 as A, table2 as B WHERE (A.conditions) AND  (A.ID = B.ID)
    

提交回复
热议问题