4

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

StevieG
  • 8,639
  • 23
  • 31
Deepak Kumar
  • 3,623
  • 9
  • 32
  • 32

2 Answers2

14

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.

Mikael Eriksson
  • 136,425
  • 22
  • 210
  • 281
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
StevieG
  • 8,639
  • 23
  • 31