2011-08-22 126 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