[英]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.