关于SQL查询重复语句

[复制链接]
查看11 | 回复5 | 2009-6-19 12:39:33 | 显示全部楼层 |阅读模式
经过试验,下面的方法能满足你的要求。Sql Server里面如果没有设定主键而删除重复数据很麻烦:一:保留重复记录中的一条记录,其他全部删除。--1:建立临时表,把不重复的数据转存select distinct * into #Tmp from 表名;--2:删除原表数据truncate table 表名;--3:将数据导回insert into 表名 select * from #Tmp;--4:删除临时表drop table #Tmp;******************如果是oracle的话,把 rowid 查出来,按照rowid删除就可以了。select rowid,表名.* from...
回复

使用道具 举报

千问 | 2009-6-19 12:39:33 | 显示全部楼层
你表里就俩字段的话不太好弄,如果有第三个字段select post_content,post_title from wp_posts group by post_content,post_title having count(*)>1先看看有多少重复的假设你表中还有id的一个字段select min(id),post_content,post...
回复

使用道具 举报

千问 | 2009-6-19 12:39:33 | 显示全部楼层
你的图中post_content全一样,post_title有两种,这算不算重复呀?我按post_content重复就查找出来。查重:select post_content,post_title from wp_posts group by post_content having count(post_content)>1删除要先将数据查询到...
回复

使用道具 举报

千问 | 2009-6-19 12:39:33 | 显示全部楼层
使用临时表求出重复记录select userid from t_name group by userid having count(*) > 1求出不重复记录select distinct * into #a1 from t_name where userid in select userid from t_name group by u...
回复

使用道具 举报

千问 | 2009-6-19 12:39:33 | 显示全部楼层
select * from table1 b where bill_id=(select top 1 bill_id from table1 a where exists(select top 1 column1 from table1 where column1=a.column1 group by column1 having count(*)>1 or...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行