sql

在一条sql语句中能用distanc吗?select t_ill_info.idx,t_ill_info.illname,t_ill_info.display from t_ill_info inner join t_ill_sameword on t_ill_info.idx=t_ill_sameword.typeid 
where t_ill_sameword.tongyici like '%'+@tongyici+'%' order by t_ill_info.illname 怎么按t_ill_info.idx进行分组呢?现在查询出来的有重复的项

解决方案 »

  1.   

    这种情况下应该 
    select t_ill_info.idx,t_ill_info.illname,t_ill_info.display from t_ill_info 
    where t_ill_sameword.tongyici like '%'+@tongyici+'%'
    and exists(select 1 from t_ill_sameword where t_ill_info.idx=t_ill_sameword.typeid)
    order by t_ill_info.illname  
      

  2.   

    select t_ill_info.idx,t_ill_info.illname,t_ill_info.display from t_ill_info inner join t_ill_sameword on t_ill_info.idx=t_ill_sameword.typeid  group by t_ill_info.idx,t_ill_info.illname,t_ill_info.display having count(t_ill_info.idx)>0 
    and t_ill_sameword.tongyici like '%'+@tongyici+'%' order by t_ill_info.illname  
      

  3.   

    用了别的方法select t_ill_info.idx,t_ill_info.illname,t_ill_info.display from t_ill_info 
    where t_ill_info.idx in (select t_ill_sameword.typeid from t_ill_sameword 
    where t_ill_sameword.tongyici like '%'+@tongyici+'%' ) order by t_ill_info.idx