数据库数据查重

rowid是数据库中存数据之后,自动为那条数据配上的编码,每条数据所拥有的编码都不相同,我们可以根据rowid快速的确定某一列,然后对其操作。

这是数据库查重,并且删除所有重复数据,只保留一条,这里我是根据ID这一列查重,多列查重的方法类似。

delete from tb where (id) in
(select Name from tb group by Name having count(id) >1)
and rowid not in (select min(rowid) from tb group by Name having count(id)>1);
commit;

将不同地区的数据查询出来,并且相同地区数据放在一起,从上到下,依次列在一张表上。

A  union all  B 将两个表连接起来,上边全部是表A,下边全部是表B,两个表的数据全部显示出来,不管是否重复。

A  union  B  将两个表连接起来,与union all相似,不过如果两个表中如果有重复的数据,则会把重复的数据删除,只保留一个,并且排序会打乱,并不是上方全部是表A,下方是表B。

select * from tb t WHERE DIQU='朝阳' union all select * from tb t WHERE DIQU='经开' union all
select * from tb t WHERE DIQU='南关' union all select * from tb t WHERE DIQU='绿园'
union all select * from tb t WHERE DIQU='二道'union all select * from tb t WHERE DIQU='高新'
union all select * from tb t WHERE DIQU='汽车城'union all select * from tb t WHERE DIQU='德惠'
union all select * from tb t WHERE DIQU='宽城'union all select * from tb t WHERE DIQU='净月'
union all select * from tb t WHERE DIQU='榆树'

原文地址:https://www.cnblogs.com/cwmizlp/p/7053744.html