Recently encountered a MySQL subquery at the time of development to delete the original table data problem. On the internet also saw a lot of methods, basic is also the egg (not write too messy is too slow).
The company DBA gave a very good solution, refreshing.
DELETE fb.* from Froadbill.bill FB left JOIN froadbill.refundinfo br in br.billseqno = Fb.seq_no WHERE br.billseqno is NUL L and Fb.create_time >='20150102000000'and fb.create_time <' 20150302000000' ;
Froadbill.bill is a bill sheet (about 1kw data) and Froadbill.refundinfo is a refund form (about 10w data). This SQL is the data to delete the bill table 20150102-20150302 and not the refund form. This syntax avoids the inefficient use of in or not in SQL.
You can also use this notation for data insertion:
INSERT into Froadbill.bill_history SELECT DISTINCT fb.* from Froadbill.bill FB left joins Froadbill.refundinfo BR on Br.bil lseqno = Fb.seq_no WHERE br.billseqno is NULL and fb.create_time >= ' 20150102000000 ' and fb.create_time < ' 201503 02000000 ';
Work essay--mysql delete the original table data