如何删除重复的记录

csteven 2002-11-01 11:26:15
??
...全文
30 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
playyuer 2002-11-11
  • 打赏
  • 举报
回复
参阅《程序员》杂志 2002年11月: 《一道褒贬不一的 SQL 考试题》一文,大概是第一题:
CrazyFor 2002-11-11
  • 打赏
  • 举报
回复
修正:
delete from table
where id not in (select max(id) from table group by id)
CrazyFor 2002-11-11
  • 打赏
  • 举报
回复
delete from table
where id not in (select id from table)
newyu1127 2002-11-11
  • 打赏
  • 举报
回复
老纳的方法很好,我赞同,问题是:如果我没有ID这一字段,而我又要作如下的判断,如果表中有重复的记录,则执行老纳所言的方法,如果没有重复的记录则不做任何事。这个判断怎么写呢?请赐教。
蓝天 2002-11-01
  • 打赏
  • 举报
回复
select distinct * into #tmp from yourtable
truncate table yourtable
insert yourtable select * from #tmp
蓝天 2002-11-01
  • 打赏
  • 举报
回复
都删啊?一条都不留?
chump 2002-11-01
  • 打赏
  • 举报
回复
delete table1
from table1 a,
(select id from table1 group by id having count(id)>1) b
where a.id=b.id
glmcglmc 2002-11-01
  • 打赏
  • 举报
回复
delete from tmp
where id in (
select id from (
select id,count(id) as dup_count from tmp group by id) a
where a.dup_count>1
)
glmcglmc 2002-11-01
  • 打赏
  • 举报
回复
delete from table
where id in (
select id from (
select id,count(id) as dup_count from talbe group by id)
where dup_count>1
)
happydreamer 2002-11-01
  • 打赏
  • 举报
回复
chumpg和lmcglmc你们把所有相同记录都delete了,sky_blue做法是保留了一项
happydreamer 2002-11-01
  • 打赏
  • 举报
回复
比较赞成sky_blue的方法

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧