日期:2014-05-18  浏览次数:20526 次

请教一个表关联的问题
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 tb1
left join 
(select id from tb2 where tb2.value in (1,2) and tb2.stat<>'x') as tb2 
on tb1.id=tb2.id
where tb2.id is null