Move data from one table to another
This question seems to be answered multiple times. However none match the criteria I 开发者_StackOverflowneed.
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?
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.
精彩评论