Select a.id,a.name,
(case when exists(Select 1 from 表b where id = tmp.id) then 1 else 0 end) as isSelected
from 表a tmp

解决方案 »

  1.   

    select a.id,a.name,iif(isnull(id,-1)=-1,0,1) as isselected from a left join b on a.id=b.id
      

  2.   

    select a.*,isselected=(case when exists(select 1 from 表b where id=aa.id) then 1 else 0 end) from 表a aa
      

  3.   

    或者:select *,isselected=isnull((select max(1) from 表b where id=aa.id),0)
    from 表a aa
      

  4.   

    Select a.id,a.name,
    isnull((Select top 1 1 from 表b where id = tmp.id),0) isSelected
    from 表a tmp