I have 3 tables
drop table #temp;
create table #temp(id int,name varchar(50))
insert into #temp values(1,'ABC');
insert into #temp values(2,'XYZ');
select * from #temp
drop table #table_link;
create table #table_link(id int,temp_id int,temp2_id int)
insert into #table_link values(1,1,1);
insert into #table_link values(2,1,2);
select * from #table_link
drop table #temp2;
create table #temp2(id int,active_tag bit);
insert into #temp2 values(1,0)
insert into #temp2 values(2,1)
I desired result is get all rows in #temp table and active_tag=1 with #table_link that is.
id | name | #temp2_id |
1 | ABC | 2 |
2 | XYZ | NULL |
I tried query is
select * from #temp t
left join #table_link tl on tl.temp_id=t.id
inner join #temp2 t2 on t2.id=tl.temp2_id and t2.active_tag=1
In this query i get only ABC row only.I used left join ,why XYZ row doesn't get.Currently Result is coming like this
id | name | #temp2_id |
1 | ABC | 2 |
Please Explain why it doesn't work ?