接任务,赚取用不完的金币中国教程网
《Photoshop专家讲堂》光盘热售
参与论坛活动,快速赚取金币精品素材,中英文字体
发新话题
打印

求SQL写法:在表中求出一字段有相等值的纪录.

求SQL写法:在表中求出一字段有相等值的纪录.


初学SQL,我的表中有一个字段中有很多数据是相等的,也就是这个字段有重复值,有重复的值有多种,每一种又有多个,请问怎样把这个字段有重复值的相关纪录分组查出来,把这个字段有唯一值的纪录过滤掉,谢谢!  
---------------------------------------------------------------  

select  a.*  from  tablename  as  a,(  
select  fieldname  from  tablename  group  by  fieldname  
having  count(*)  >1  
)  as  b  
where  a.fieldname=b.fieldname  
order  by  a.fieldname  




---------------------------------------------------------------  

select  yourtable.*  from  yourtable  where  exists  (select  1  from  yourtable  x  where  yourtable.fieldname=x.fieldname  group  by  fieldname  having  count(*)>1)
发新话题 返回列表