Hi,
I have an issue in understanding a very simple yet interesting query concerning 2 right outer joins with 'non-sequential' on-expressions. Here is the query:
select * from C
right outer join A on A.F1 = C.F1
right outer join B on B.F1 = C.F1;
Here are the tables:
create table A ( F1 varchar(200));
create table B ( F1 varchar(200));
create table C ( F1 varchar(200));
Here are some rows:
insert into A values ('A');
insert into A values ('B');
insert into A values ('C');
insert into B values ('B');
insert into B values ('C');
insert into B values ('D');
insert into C values ('A');
insert into C values ('C');
insert into C values ('D');
Note: The query select * from C right outer join A on A.F1 = C.F1 right outer join B on B.F1 = C.F1; join expressions both refers to table C.
The query returns (in columns then rows)
(NULL,NULL, B),(C, C, C).(NULL, **NULL**, D)
and I expected (in my little understanding of SQL)
(NULL,NULL, B),(C, C, C),(NULL, **D**, D)
What is the logical sequence whereby SQL (tested on Microsoft SQL as well as MySQL) get to these values.
In my "execution" sequence I sit with on table A values of A, null (for B), C, null (for D) and in Table B, null (for A), B, C, D before the "product" is amalgamated with C (B,C,D).
Gawie PS: I have test this using MySQL as well as Microsoft SQL 2008... with the same results.