Delete duplicate records in a database table

Source: Internet
Author: User

Oracle
Select *  fromGcfr_t_vch_delete EWHEREE.rowid<(SELECT Max(X.rowid) fromGcfr_t_vch_delete XWHEREX.vchno=E.vchno andE.type=X.type andE.curragency=x.curragency);--orSelect *  fromGcfr_t_vch_delete EWHEREE.rowid>(SELECT min(X.rowid) fromGcfr_t_vch_delete XWHEREX.vchno=E.vchno andE.type=X.type andE.curragency=X.curragency);

The type of voucher, the number, the unit is the basis for judging the repetition. Delete Duplicates is to delete the superfluous and leave only one. The meaning of the above SQL is to find out the duplicate records, with a maximum value of the standard, the less than his are deleted. Or, by the smallest criterion, delete the larger than his. This is exactly what is needed.

Oracle uses ROWID to ensure the uniqueness of the data, but it is also possible to use a table field, but it is best to be the primary key in order to ensure the uniqueness of the fields.

Mysql
Select *  fromGcfr_t_vch_delete EWHEREE.guid<(SELECT Max(X.guid) fromGcfr_t_vch_delete XWHEREX.vchno=E.vchno andE.type=X.type andE.curragency=x.curragency);--orSelect *  fromGcfr_t_vch_delete EWHEREE.guid>(SELECT min(X.guid) fromGcfr_t_vch_delete XWHEREX.vchno=E.vchno andE.type=X.type andE.curragency=X.curragency);

MySQL has no rowid here, in the case of GUIDs, the GUID is the primary key of the table.

Delete duplicate records in a database table

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.