只需判断一下即可,根据你的题目意思应该是a表的id和b表的id相关联。
select *, case when (select count(*) from b where id = a.id)>0 then 1 else 0 end as flag from a如果你是想a表和b表的字段和id这两列都一样,才将flag显示为1的话,用下面的查询:
select *, case when (select count(*) from b where id = a.id and 字段 = a.字段)>0 then 1 else 0 end as flag from a