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
画蛇添足了,还是回来: select distinct a.* from table2 a,table1 b where a.Gname like '%'+rtrim(b.Gname)+'%' and b.bgid=1
查组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
where (a.Gname like '%,'+rtrim(b.Gname)+'%' or a.Gname like '%'+rtrim(b.Gname)+',%')
and b.bgid=1
select distinct a.* from table2 a,table1 b
where a.Gname like '%'+rtrim(b.Gname)+'%'
and b.bgid=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