I'm trying to filter out a table using filter in the outer join clause rather than a where clause. When i try to do so i'm getting unexpected results. The whole table is returned as though i didn't apply the filter at all.
When I run this example, i get different results for the last two queries. I would expect them to have the same results but it's not the case. What is going on here?
declare @a table
(
id int
,content varchar(100)
)
declare @b table
(
id int
,content varchar(100)
)
insert into @a (id,content) values (1,'Apple')
insert into @a (id,content) values (2,'Banana')
insert into @a (id,content) values (3,'Orange')
insert into @b (id,content) values (1,'Juice')
insert into @b (id,content) values (2,'Peel')
insert into @b (id,content) values (3,'Julius')
--basic outer join
select * from @a a left join @b b on a.id=b.id
--outer join with where clause filter
select * from @a a left join @b b on a.id=b.id where a.id=1
--outer join with join clause filter
select * from @a a left join @b b on a.id=1 and a.id=b.id