一、數(shù)據(jù)庫中的去重操作(刪除數(shù)據(jù)庫中重復(fù)記錄的SQL語句)主要有三種方法
(1)、rowid方法
(2)、group by 方法
(3)、distinct方法
1、用rowid方法
根據(jù)Oracle帶的rowid屬性,可以進行判斷是否存在重復(fù)語句;
(1)、查出表1和表2中name相同的數(shù)據(jù)
Select * from table1 a Where rowid !=(select max(rowid) from table2 b Where a.name1 = b.name1 And a.name2 = b.name2......) 12345
(2)、刪除表1和表2 中name相同的所有數(shù)據(jù)
Delete from table1 a Where rowid !=(select max(rowid) From table2 b Where a.name1 = b.name1 And a.name2 = b.name2.......) 12345
2、用group by方法
主要用于分組統(tǒng)計,一般都是使用在聚合函數(shù)中使用;
(1)、查數(shù)據(jù)
Select count(num), max(name) from student 列出表中的重復(fù)的記錄數(shù)和學(xué)生名字的屬性,
Group by num Having count(num) 12
1 并按照num分組后找出表中num列出現(xiàn)次數(shù)大于一次的。
(2)、刪除數(shù)據(jù)
Delete from student Group by num Having count(num)>1 123
//刪除表中num列所有重復(fù)的數(shù)據(jù)
3、用distinct方法
一般用于比較小的表進行去重,會過濾掉多余的重復(fù)記錄,返回不重復(fù)的記錄或字段;文章來源:http://www.zghlxwxcb.cn/news/detail-700915.html
(1)select distinct name from student文章來源地址http://www.zghlxwxcb.cn/news/detail-700915.html
到了這里,關(guān)于數(shù)據(jù)庫去重(MYSQL和ORACLE)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!