当前位置: 代码迷 >> Sql Server >> 请问一个表关联的有关问题
  详细解决方案

请问一个表关联的有关问题

热度:60   发布时间:2016-04-27 19:17:13.0
请教一个表关联的问题
tb1 tb2  
根据id关联
tb2有 id,value,stat
当tb2的value=‘1’或‘2’ stat<>‘x'
则主表不显示这条记录

比如现在id=001
tb2中 
id=001 value=1 stat=’‘
id=001 value=3 stat=’x'
怎么能让 主表不显示 id=001这条数据

------解决方案--------------------
SQL code
select tb1.*from tb1left join (select id from tb2 where tb2.value in (1,2) and tb2.stat<>'x') as tb2 on tb1.id=tb2.idwhere tb2.id is null
  相关解决方案