create table #vent (id int, num int, comments varchar(100))
create table #old (id int, comments varchar(100))
insert #vent values (1,0,'Shows up anyway')
insert #vent values (2,1,'Shows up if vent=0 in join')
insert #vent values (3,0,'Shows up anyway')
insert #vent values (4,1,'Shows up if vent=0 in join')
insert #vent values (5,0,'Shows up anyway')
insert #old values (1,'shows up anyway')
insert #old values (2,'never shows')
insert #old values (3,'shows up anyway')
insert #old values (4,'never shows')
GO
-- query1
select *
from #vent
left join #old on #old.id = #vent.id and #vent.num = 0
-- query2
select *
from #vent
left join #old on #old.id = #vent.id
where #vent.num = 0
GO
/*
-- query 1
id num comments
1 0 Shows up anyway 1 shows up anyway
2 1 Shows up if vent=0 in join NULL NULL -- note how the join doesnt show any #old columns because only join if num = 0
3 0 Shows up anyway 3 shows up anyway
4 1 Shows up if vent=0 in join NULL NULL -- note how the join doesnt show any #old columns because only join if num = 0
5 0 Shows up anyway NULL NULL -- there isnt a id = 5 in #old
-- query 2
id num comments
1 0 Shows up anyway 1 shows up anyway
3 0 Shows up anyway 3 shows up anyway
5 0 Shows up anyway NULL NULL
*/
|