group by 和having count的怪问题

jett_xu 2006-11-25 10:12:04
表如下:
ID NAME
1 aa
1 bb
2 cc
我用
select * from table group by id having count(id)>1
结果是
id name
1 aa
怎么样才能出来结果
id name
1 aa
1 bb
我用mysql 5027
thanks.
...全文
257 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
jett_xu 2006-11-25
  • 打赏
  • 举报
回复
用你第一个方法搞定,thanks.
jett_xu 2006-11-25
  • 打赏
  • 举报
回复
第二个方法是个好方法,可惜我的是文本的
为什么MYSQL不支持我仍未应该支持的方法呢.
mschen 2006-11-25
  • 打赏
  • 举报
回复
/* or you may try like this */

select * from aa
where id in (select id from aa group by id having count(*)>1);
mschen 2006-11-25
  • 打赏
  • 举报
回复
/* try like this */

select *
from 表 a
where exists(select 1 from 表 where id=a.id and name<>a.name);

56,677

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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