- editing my question *
I have a set of tables. When I filter on the second table, t2, I'd still like to get all rows of t1.
SQL script is below. I feel like I'm getting close while tinkering, but I just can't make it happen.
In short, I need t2's rows when applicable, but all of t1's rows with nulls in the other columns.
Thanks.
create table t1 ( id int identity(1,1), parentName varchar(20) null )
create table t2 ( id int identity(1,1), t1id int not null, childName varchar(20) null )
create table t3 ( id int identity(1,1), t2id int not null, gChildName varchar(20) null )
insert into t1 ( parentName ) values ( 'bob' )
insert into t1 ( parentName ) values ( 'john' )
insert into t2 ( childName, t1id ) values ( 'irving', 1 )
insert into t2 ( childName, t1id ) values ( 'parna', 1 )
insert into t2 ( childName, t1id ) values ( 'mike', 1 )
select
t1.id,
t1.parentName,
t2.id,
t2.childName
from t1 left outer join t2
on t2.t1id = t1.id
where t2.childName = 'mike'
-- what i'd LIKE is:
-- 1, bob, 3, mike
-- 2, john, null, null
drop table t3
drop table t2
drop table t1