MySQL在表之间移动行 [英] mysql move row between tables

查看:58
本文介绍了MySQL在表之间移动行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个表,table1和table2.

I have 2 tables, table1 and table2.

我在table1中有一行,想要将其移至table2并将其从table1中删除.基本上是剪切+粘贴.

I have a row in table1 and want to move it to table2 and remove it from table1. Basically, a cut+paste.

我正在使用php.我当前的计划是从table1中进行选择,将数据存储在php中,插入table2中,然后从table1中删除.这似乎是一个非常漫长的过程.

I am using php. My current plan is to select from table1, store data in php, insert into table2, then delete from table1. This seems like a very long process.

这真的是最好的方法吗?

Is this really the best way to do this?

推荐答案

您将至少需要2个查询:

You're going to need at least 2 queries:

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的更短方法

I see no shorter way of doing this using MySQL

这篇关于MySQL在表之间移动行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆