我有 2 个表,table1 和 table2。
我在 table1 中有一行,想将它移到 table2 并从 table1 中删除。基本上,剪切+粘贴。
我正在使用 php。我目前的计划是从table1中选择,将数据存储在php中,插入到table2中,然后从table1中删除。这似乎是一个非常漫长的过程。
这真的是最好的方法吗?
最佳答案
您至少需要 2 个查询:
INSERT INTO table2 (column_name1, column_name2) SELECT column_name1, column_name2 FROM table 1 WHERE <insert_where_clause_here>
DELETE FROM table1 WHERE <your_where_clause>
我认为没有比使用 MySQL 更短的方法了
关于mysql 在表之间移动行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5420156/