简体   繁体   English

使用LEFT OUTER JOIN时添加条件

[英]Add condition while using LEFT OUTER JOIN

I have two table i want to add one condition while using 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

i want only those record which is have visible = 1 that is true but query ignore the condition and one thing i must have to use left outer join coz i want record from left table even record not present in right table how to check the condition that i will get only those record from left table in which visible is 1 我只想要那些有可见= 1的记录是真的但查询忽略条件和一件事我必须要使用左外连接因为我想要从左表记录甚至记录不存在于右表中如何检查条件我将只从左表中获得可见为1的那些记录

Try this 尝试这个

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

I moved tt.visible = 1 to the where clause instead. 我将tt.visible = 1移到了where子句中。 vct.employee = 63 need to stay in the join because otherwise you would not have an outer join. vct.employee = 63需要保留在连接中,否则你将没有外连接。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM