mysql-将行从一个表移动到另一个表 [英] mysql - move rows from one table to another
本文介绍了mysql-将行从一个表移动到另一个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有两个结构相同的表,如何将一组行从一个表移到另一个表?
If i have two tables that are identical in structure, how can i move a set of rows from 1 table to the other?
将从选择查询中确定行集.
The set of rows will be determined from a select query.
例如:
customer table
person_id | person_name | person_email
123 tom tom@example.com
persons table
person_id | person_name | person_email
样本选择为:
select * from customer_table where person_name = 'tom';
我要将行从客户表移到个人表
I want to move the row from customer table to person table
理想情况下,从原始表中删除数据,但这不会破坏交易.
Ideally removing the data from the original table, but this wouldnt be a deal breaker.
推荐答案
简单的 插入SELECT 语句:
A simple INSERT INTO SELECT statement:
INSERT INTO persons_table SELECT * FROM customer_table WHERE person_name = 'tom';
DELETE FROM customer_table WHERE person_name = 'tom';
这篇关于mysql-将行从一个表移动到另一个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文