sql语句 判断表数据是否存在另一个表中
1个回答
展开全部
只需判断一下即可,根据你的题目意思应该是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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询