
SQL中用什么语句去掉表中重复的元组
避如下面有两条相同元组:01Michaelmath02JennyEnglish01Michaelmath...
避如下面有两条相同元组:
01 Michael math
02 Jenny English
01 Michael math 展开
01 Michael math
02 Jenny English
01 Michael math 展开
6个回答
展开全部
删不了。
最好的方法是把ID那列做一个主键,这样在插入时就不会有重复的。在显示的时候倒是可以。
最好的方法是把ID那列做一个主键,这样在插入时就不会有重复的。在显示的时候倒是可以。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
一般的数据库设计里都是不会存在重复行的,都有个主键约束或唯一约束什么的,sql语句不大好弄,在企业管理器中倒是好办
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
create table mytab( id varchar2(2), name varchar2(20), name2 varchar2(20))
insert into mytab
select '01','Michael', 'math' from dual
union all
select '02','Jenny', 'English' from dual
union all
select '01','Michael', 'math' from dual
select distinct * from mytab
insert into mytab
select '01','Michael', 'math' from dual
union all
select '02','Jenny', 'English' from dual
union all
select '01','Michael', 'math' from dual
select distinct * from mytab
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select
name,ip,min(time)
from
table
group
by
name,ip
name,ip,min(time)
from
table
group
by
name,ip
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
1、将重复的记录记入temp1表:
select [标志字段id],count(*) into temp1 from [表名]
group by [标志字段id]
having count(*)>1
2、将不重复的记录记入temp1表:
insert temp1
select [标志字段id],count(*) from [表名]
group by [标志字段id]
having count(*)=1
3、作一个包含所有不重复记录的表:
select * into temp2 from [表名]
where 标志字段id in(select 标志字段id from temp1)
4、删除重复表:delete [表名]
5、恢复表:
insert [表名]
select * from temp2
6、删除临时表:
drop table temp1
drop table temp2
select [标志字段id],count(*) into temp1 from [表名]
group by [标志字段id]
having count(*)>1
2、将不重复的记录记入temp1表:
insert temp1
select [标志字段id],count(*) from [表名]
group by [标志字段id]
having count(*)=1
3、作一个包含所有不重复记录的表:
select * into temp2 from [表名]
where 标志字段id in(select 标志字段id from temp1)
4、删除重复表:delete [表名]
5、恢复表:
insert [表名]
select * from temp2
6、删除临时表:
drop table temp1
drop table temp2
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询