查找相同字段的sql语句怎么写?

xl_xl 2002-04-03 02:09:38
表Information中有四个字段:ID,Name,Sex,Position
ID为主键,现在我想查找姓名一样的记录,sql语句应该怎么写,谢谢。
...全文
142 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
xl_xl 2002-04-03
  • 打赏
  • 举报
回复
先把分给了再说
xl_xl 2002-04-03
  • 打赏
  • 举报
回复
to haiwer(海阔天空--回复语句只对MSSQL有效):
报:select附件有错。
net_steven 2002-04-03
  • 打赏
  • 举报
回复
to haiwer:
对不起,我写错了,本意是要象SE1() 写的。
N_chow 2002-04-03
  • 打赏
  • 举报
回复
Select A.* From Information A INNER JOIN (Select name from Information group by name having count(*)>1) B
ON A.name=b.Name
SE1 2002-04-03
  • 打赏
  • 举报
回复
稍作补充:
select *
from Information
where Name in (
select Name from Information group by name having count(*)>1)

效率更高!
昵称被占用了 2002-04-03
  • 打赏
  • 举报
回复
以上留ID最大的一条。
昵称被占用了 2002-04-03
  • 打赏
  • 举报
回复
delete Information
from Information a,
(
select max(id) as id,Name from Information
group by name having count(*)>1
) as b
where a.id<>b.id
and a.name=b.name
xl_xl 2002-04-03
  • 打赏
  • 举报
回复
查找出相同姓名的记录后,删除其中的一个,我的意思是姓名相同的记录保留一条。
x_zing 2002-04-03
  • 打赏
  • 举报
回复
删除哪一个啊?
warning 2002-04-03
  • 打赏
  • 举报
回复
稍作补充:
select * from Information a
where exists (
select Name from Information where name=a.name group by name having count(*)>1)
xl_xl 2002-04-03
  • 打赏
  • 举报
回复
如果要删除其中相同记录的一条呢?
xl_xl 2002-04-03
  • 打赏
  • 举报
回复
如果要删除其中的一个呢?
昵称被占用了 2002-04-03
  • 打赏
  • 举报
回复
狼兄,你把那个WHERE去掉了就不对了!
net_steven 2002-04-03
  • 打赏
  • 举报
回复
稍做补充:
select * from Information
where exists (
select Name from Information group by name having count(*)>1)
order by name
昵称被占用了 2002-04-03
  • 打赏
  • 举报
回复
select * from Information
where exists (
select Name from Information where name=a.name group by name having count(*)>1)

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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