2011-08-22 107 views
1

我有两个表我想补充一个条件,而使用LEFT OUTER JOIN同时使用LEFT OUTER JOIN

select tt.description,tt.visible,vct.currvalue 
from tblemployee tt 
left outer join viwcurrentemployee vct on vct.transitiontype = tt.cid 
             and vct.employee = 63 
             and tt.visible = 1 
order by tt.cid 

我想只有那些是有肉眼可见的纪录= 1即是真实的,但查询忽视添加条件条件和一件事我必须使用左外部连接因为我想从左表中记录甚至记录不存在于右表中如何检查条件,我将只从左表中看到那些可见的记录1

回答

7

试试这个

select tt.description, 
     tt.visible, 
     vct.currvalue 
from tblemployee tt 
    left outer join viwcurrentemployee vct 
    on vct.transitiontype = tt.cid and 
     vct.employee = 63 
where tt.visible = 1 
order by tt.cid 

我把tt.visible = 1改为了where子句。 vct.employee = 63需要留在联接中,否则您不会有外部联接。

2
select tt.description,tt.visible,vct.currvalue 
from tblemployee tt 
left outer join viwcurrentemployee vct on vct.transitiontype = tt.cid 
             and vct.employee = 63 
where tt.visible = 1 
order by tt.cid