两个表 Diary 日志表 Advertisement发帖表两个表关联 但是查出的数据不是一一对应的 就是某列有重复的数据  怎样去除重复的数据 也就是某列重复的数据只显示一个
DiaID          AdverTitle
101                 132
101                 326
101                 158
101                 102
102                 178
有办法让101只显示一次吗  

解决方案 »

  1.   

    select * from TableName as out 
    where exists(select * from  
    (select DiaID from TableName group by DiaID having count(*) > 1) as b
    where DiaID = out.DiaID)
      

  2.   

    Diary 和 Advertisement  是关联的   DiaID 是 Diary表的 AdverTitle是Advertisement 表的
      

  3.   

    这个问题就没人能解决吗   重复的显示NULL 也行
      

  4.   

    合并生成一个临时表,或者要使用时存到一个DataTable, 然后在里面想怎样搞就怎样搞
      

  5.   


    正解
    select distinct  * from TableName as out
    where exists(select * from
    (select DiaID from TableName group by DiaID having count(*) > 1) as b
    where DiaID = out.DiaID)
    试试
      

  6.   

    多对多的联接查询除了distinct还需要加上group by。另外就是你要的数据格式在逻辑上是不是能支持你想要的效果。
      

  7.   

    oracle关联查询好像就有去掉重复的功能!