使用LEFT OUTER JOIN时添加条件 [英] Add condition while using LEFT OUTER JOIN

查看:320
本文介绍了使用LEFT OUTER JOIN时添加条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表,我想在使用左外连接时添加一个条件

 选择tt.description,tt.visible ,vct.currvalue 
来自tblemployee tt
在vct.transitiontype = tt.cid
和vct.employee = 63
和tt.visible = 1 $ b上的外部加入viwcurrentemployee vct $ b由tt.cid命令

我只希望那些具有visible = 1的记录为true但是查询忽略该条件,我必须使用左外连接coz来做一件事,我想从左表记录,甚至右表中不存在记录如何检查条件,即我只会从可见表为1的左表中获取那些记录

解决方案

尝试一下

 选择tt.description,
tt.visible,
vct.currvalue
从tblemployee tt tt
左外加入viwcurrentemployee vct
在vct.trans上itiontype = tt.cid和
vct.employee = 63
,其中tt.visible = 1
由tt.cid


我将 tt.visible = 1 移到where子句。 vct.employee = 63 需要留在联接中,否则您将没有外部联接。


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

解决方案

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. vct.employee = 63 need to stay in the join because otherwise you would not have an outer join.

这篇关于使用LEFT OUTER JOIN时添加条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆