简体   繁体   English

如何在MySQL中将数据从一个表移到另一个表?

[英]How do I move data from one table into another in MySQL?

I have the following query which pulls 1000 rows of data: 我有以下查询,它提取1000行数据:

select barcode, type from collections where user = 'myusername'

I need to move this data to my new collectors_collections table. 我需要将此数据移到新的collectors_collections表中。 The user column is now labeled username . user列现在标记为username

What is the quickest way to do this? 最快的方法是什么? A query of some kind or some other way? 某种或其他方式的查询? I am using the latest MySQL Workbench. 我正在使用最新的MySQL Workbench。

You could try running this query: 您可以尝试运行此查询:

INSERT INTO
    collectors_collections(barcode, type, username)
SELECT
    barcode,
    type,
    `user`
FROM
    collections
WHERE
    `user` = 'myusername';

Well, a simplistic approach which I would use it to just cut and paste the results of your selection into a text editor. 好吧,我将使用它来将选择的结果剪切并粘贴到文本编辑器中的简单化方法。 And perform some simple search/replaces to create insert statements for your new table. 并执行一些简单的搜索/替换为新表创建插入语句。 Then just paste the new insert statements into your mysql client. 然后只需将新的插入语句粘贴到您的mysql客户端中即可。

I assume you are not wanting this functionality with a running program. 我假设您不希望正在运行的程序具有此功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在mysql中将数据从一个表插入到另一个表? - How do I insert data from one table to another in mysql? 将数据从一个 MySQL 表移动到另一个表 - Move data from one MySQL table to another 如何将图像数据从一张桌子移动到另一张桌子? - How can I move image data from one table to another? 如何在MySQL中使用SELECT语句从一个表中获取数据,并从另一表中覆盖数据? - How do I take data from one table, and overwrite it from another table, with a SELECT statement in MySQL? 如何将一行从一个表移动到mysql中的另一个表? - How to move one row from one table, to another table in mysql? MySql表类型,如何将列数据从一个表自动绘制到另一个表? - MySql table type, how do I draw column data from one table to another automatically? MySQL:使用不同的架构将数据从一个表移动到另一个表 - MySQL: Move data from one table to another with different schema 使用转义值将mysql数据从一个表移动到另一个表 - Move mysql data from one table to another with escaped values 最好的MySQL方式将数据从表移动到另一个带结点的方法 - Best MySQL way to move data from table to another one with junction 如何使用游标创建存储过程以通过验证将数据从一个表移动到另一表(Mysql) - How to create stored procedure using cursor to move data from one table to another table with validation ( Mysql)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM