I would like to move old records from a table to another one.
If I do this:
INSERT INTO archived_item SELECT * FROM item WHERE is_sold=1 AND sold_at < DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH)
I would just copy rows. But I need to move them.
I don’t think running this query after the previous one is ideal:
DELETE FROM item WHERE is_sold=1 AND sold_at < DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH)
I wouldn’t like to use any external tool either.
Is it possible to achieve that via SQL?
As far as I know, the only way to do this is to run the INSERT query and then run a delete query on the source table. There is no other way to achieve it.