1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
drop table a;
drop table b;
drop table c;
create table c (id int not null identity primary key, vc varchar(10) not null);
create table b (id int not null identity primary key, c_id int null references c (id), vb varchar(10) not null);
create table a (id int not null identity primary key, b_id int null references b (id), va varchar(10) not null);
insert into c (vc) values ('C1');
insert into c (vc) values ('C2');
insert into b (c_id, vb) values (1, 'B1');
insert into b (c_id, vb) values (2, 'B2');
insert into b (c_id, vb) values (null, 'B3');
insert into a (b_id, va) values (1, 'A1');
insert into a (b_id, va) values (2, 'A2');
insert into a (b_id, va) values (3, 'A3');
insert into a (b_id, va) values (null, 'A4');
select a.va, b.vb, c.vc
from a
left outer join b on b.id = a.b_id
inner join c on c.id = b.c_id;
select a.va, b.vb, c.vc
from a
left outer join b on b.id = a.b_id
left outer join c on c.id = b.c_id;
select a.va, b.vb, c.vc
from a
left outer join
(
b
inner join c on c.id = b.c_id
)
on b.id = a.b_id;
select a.va, b2.vb, b2.vc
from a
left outer join
(
select b.id, b.vb, c.vc
from b
inner join c on c.id = b.c_id
) b2
on b2.id = a.b_id; |
Partager