Work essay--mysql delete the original table data

Source: Internet
Author: User
Tags mysql delete

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.