文档详情

几个删除重复记录的SQL语句(Several SQL statements that delete duplicate records).doc

发布:2017-07-21约5.2千字共8页下载文档
文本预览下载声明
几个删除重复记录的SQL语句(Several SQL statements that delete duplicate records) Several SQL statements that delete duplicate records 1. using the ROWID method 2. using the group by method 3. using the distinct method 1. Using the ROWID method According to the ROWID attribute of the Oracle band, to determine whether there is repetition, the statement follows: Check data: Select *, from, table1, where, ROWID, a = select max (ROWID) From, table1, B, where, a.name1=b.name1, and, a.name2=b.name2... Censored data: Delete, from, table1, where, ROWID, a = = (select, max (ROWID)) From, table1, B, where, a.name1=b.name1, and, a.name2=b.name2... 2.group by method Check data: Select count (Num), max (name) from student - lists the number of duplicate records, and lists his name attributes Group by num Having count (Num) 1 -- after grouping by num, find the num column in the table to repeat, that is, the number of occurrences is greater than once Censored data: Delete from student Group by num Having count (Num) 1 In that case, all the duplicates have been deleted. 3. using the distinct method - useful for small tables Create, table, table_new, as, select, distinct * from, table1, minux Truncate table table1; Insert, into, table1, select * from, table_new; Methods for querying and deleting duplicate records 1, find redundant redundant records in the table, and repeat records are judged by a single field (peopleId) Select * from people Where peopleId in (select, peopleId, from, people, group, by, peopleId, having, count (peopleId) ,) 2, delete redundant duplicate records in the table, repeat records are based on a single field (peopleId) to determine, leaving only the smallest record of ROWID Delete from people Where peopleId in (select, peopleId, from, people, group, by, peopleId, having, count (peopleId) ,) And, ROWID, not, in (select, min (ROWID), from, people, group, by, peopleId, having, count (peopleId), 1) 3, find redundant duplicate records in the table (multiple fields) Select * fr
显示全部
相似文档