将数据从一个表移动到另一个表
这个问题似乎已经回答过多次了。然而没有一个符合我需要的标准。
是否可以从 Mysql 中的原始表中选择(并将它们插入到另一个表中)并删除行,而无需运行所选条件两次?
例如,我可以这样做:
INSERT INTO main (SELECT * FROM temp WHERE age > 30)
DELETE FROM cache WHERE age > 30
但是,对于一个非常复杂且长时间运行的查询,查询的“匹配部分”将执行两次,而我认为应该有一个解决方案来删除所选项目,因为您已经获取了它们无论如何。
我的问题是,这可能吗?如果可能的话。如何?
This question seems to be answered multiple times. However none match the criteria I need.
Is it possible to select (and insert them in another table) and delete rows from the original table in Mysql without running the selected criteria twice?
For example I could do this:
INSERT INTO main (SELECT * FROM temp WHERE age > 30)
DELETE FROM cache WHERE age > 30
However with a very complex and long running query the 'match part' of the query would be executed twice, whilst I think that there should be a solution to delete the selected items, since you have fetched them already anyways.
My question, is this possible, and if so. How?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,你不能那样做。
如果您担心作业之间表的完整性,则应该使用事务。
No you can't do that.
You should use a transaction if you are worried about the integrity of your tables in between the job.