日期:2014-05-17  浏览次数:20366 次

SQL内联查询IN
表A 列 Num,Title,Ids; Ids Ntext 记录的是 1,2,66,109 对应表B的 
表B 列 Id,Tag

怎样查询 A对应的 B的Tag

Select *,(Select Tag From B where id in(A.Ids)) From A where Num=1

------解决方案--------------------
SQL code
select b.* from 表B b ,表A a 
where a.Num=1 and charindex(','+ltrim(b.id)+',',','+a.Ids+',')>0

------解决方案--------------------
SQL code

select * from A inner join B on A.Ids=B.Ids where A.num=1