去除重复的数据.

AOKIO 2007-01-23 01:56:34
select * from
(
select* from a
union all
select * from b
)temp
group by id,name,age
having count(*)=1
record
-----------------------
id name age
1 aa 22
1 aa 33
8 hh 44
8 oo 44
9 ii 44
9 ll 44
10 jj 44
我想得到这样的结果应该加什么条件呀?主要是要那个name,但不要重复的.

record
-------------
id name
1 aa
8 hh
8 oo
9 ii
9 ll
10 jj

先谢谢了!
...全文
174 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
中国风 2007-01-23
  • 打赏
  • 举报
回复
select *
from
(
select* from a
union--去掉all会合并重复的
select * from b
)temp
where age=(select max(age) from
(
select* from a
union--去掉all会合并重复的
select * from b
)temp2)
AOKIO 2007-01-23
  • 打赏
  • 举报
回复
在我那个SQL文的基础上能加个条件实现我想要的功能吗?
中国风 2007-01-23
  • 打赏
  • 举报
回复
max--放错位置了
select * from 表A as B
where age=(select max(age) from 表A where id =b.id and name=b.name)--保留大的
中国风 2007-01-23
  • 打赏
  • 举报
回复
select * from 表A as B
where age=max(select age from 表A where id =b.id and name=b.name)--保留大的
AOKIO 2007-01-23
  • 打赏
  • 举报
回复
不行呀,试过了.还是上面那个结果.谢谢你.
caixia615 2007-01-23
  • 打赏
  • 举报
回复
select id,name from tablename where age in(select max(age) from tablename group by name)
中国风 2007-01-23
  • 打赏
  • 举报
回复
select distinct id , name from 表--用于查询

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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