简体   繁体   English

只需少量更改,将大约1500个mysql条目复制到同一表中的最佳方法是什么?

[英]What is the best way of duplicating around 1500 mysql entries in to the same table with a small change?

I have a number of entries in a database which are assigned to a specific account within my php application. 我在数据库中有许多条目,这些条目分配给我的php应用程序中的特定帐户。 I need to duplicate all of the entries with the account_id of 5 and give the duplicated entries an account_id of 6 so they can be edited independently by the 2 different accounts. 我需要复制account_id为5的所有条目,并将重复的条目的account_id设置为6,以便可以由2个不同的帐户独立地对其进行编辑。

Normally I'd just grab all the entries with an account_id of 5 then loop through them using php inserting a new entry for each one but with 1500+ entries I imagine that's not the best idea! 通常,我只想获取一个account_id为5的所有条目,然后使用php遍历它们,为每个条目插入一个新条目,但是有1500多个条目,我想那不是最好的主意!

Is there any way to do this with SQL? 有什么办法用SQL做到这一点?

INSERT INTO table (account_id, column1, column2)
SELECT 6, column1, column2 FROM table WHERE account_id = 5;

You can find more info about this here . 您可以在此处找到有关此的更多信息。

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

相关问题 MySQL PHP从表B中获取与表A中给定列不匹配的条目的最佳方法是什么 - mysql php what is the best way to obtain from table B the entries that don't match a given column in table A 在 PHP MySQL 动态表中更改行颜色的最佳方法是什么? - What is the best way to change row colors in PHP MySQL dynamic table? 自己乘以1500个项目的列的最佳方法是什么? - What is the best way to multiply a column of 1500 items by itself? PHP / MySQL:获取新条目的最佳方法? - PHP/MySQL: Best way to fetch new entries? 更改用php / mysql创建的表行宽度的最佳方法? - best way to change width of table row created with php/mysql? 将大量(大约180mb)XML数据上传到MySQL的最佳方法是什么? - What is the best way to upload heavy(around 180mb) XML data to MySQL? 使用search / pagination将大MYSQL结果显示到表中的最佳方法是什么? - What is the best way to show large MYSQL result into table with search/pagination? 连续检查 MySQL 表更新的最佳方法是什么? - What is the best way to check MySQL table's update continuously? 使用MySQL,不选择存在于不同表中的用户的最佳方法是什么? - Using MySQL, What is the best way to not to select users that exist in a different table? 使用PHP从MySQL检索表的最佳方法是什么? - What is the best way to retrieve table from MySQL using PHP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM