找出MID=1,3是不是?
select b.mid from table1 a,table2 b where a.Bgid=1 and charindex(','+a.Gname+',',','+b.Gname+',')>0 

解决方案 »

  1.   

    select distinct a.* from table2 a,table1 b
    where (a.Gname like '%,'+rtrim(b.Gname)+'%' or a.Gname like '%'+rtrim(b.Gname)+',%')
    and b.bgid=1
      

  2.   

    画蛇添足了,还是回来:
    select distinct a.* from table2 a,table1 b
    where a.Gname like '%'+rtrim(b.Gname)+'%'
    and b.bgid=1
      

  3.   

    查组1:
    select distinct table2.mid from table1,table2 where CHARINDEX ( table1.gname,table2.gname )<>0
    and table1.bgid=1
    查所有对应关系:
    select distinct table1.bgid,table2.mid from table1,table2 where CHARINDEX ( table1.gname,table2.gname )<>0