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 ou开发者_StackOverflow中文版ter 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.
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
精彩评论