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
(case when exists(Select 1 from 表b where id = tmp.id) then 1 else 0 end) as isSelected
from 表a tmp
from 表a aa
isnull((Select top 1 1 from 表b where id = tmp.id),0) isSelected
from 表a tmp