washaw
Programmer
- Feb 13, 2008
- 48
Hello
I have four tables
tbl2 and tbl3 are children of tbl1 and tbl4 is a child of tbl3
I want to get records from tbl1 where the record should exist either in tbl2 or tbl3 or both but if it exists in tbl3 its type should be of 'eec' from tbl4
Thanks
I have four tables
Code:
create table tbl1 (id int, value varchar(100))
insert into tbl1
select 1, 'aa'
union all
select 2, 'bb'
union all select 3, 'cc'
create table tbl2 (id int, id2 int, value varchar(100))
insert into tbl2
select 1, 1, 'dd'
union all
select 2, 1, 'ee'
union all select 3, 2, 'ff'
create table tbl3 (id int, id2 int, value varchar(100))
insert into tbl3
select 1, 3, 'gg'
union all
select 2, 3, 'hh'
create table tbl4 (id int, id2 int, type varchar(100))
insert into tbl4
select 1, 1, 'eef'
union all
select 2, 3, 'eec'
tbl2 and tbl3 are children of tbl1 and tbl4 is a child of tbl3
I want to get records from tbl1 where the record should exist either in tbl2 or tbl3 or both but if it exists in tbl3 its type should be of 'eec' from tbl4
Thanks