Mysql returning clause equivalent

Unfortunately, you can’t do both insertion and deletion in one query, but you can do it all in one transaction if you are using a transactional store engine (like InnoDB). Moreover, RETURNING is supported by Oracle and PostgreSQL but not by MySQL and therefore you need to write separate delete and insert statements.

Using a transaction however, will guarantee that only the successfully copied data will be deleted from tableA. Consider the following:

begin transaction;
insert into tableB select * from tableA where 'your_condition_here';
delete from tableA where 'your_condition_here';
commit;

Leave a Comment