I'm trying to understand how the natural full outer join works, so lets consider the tables R and S.
Table R:
a | b | c | e
1 | null | 1 | 2
1 | 3 | null | 2
2 | 4 | 2 | 2
null | 5 | 2 | 2
null | 4 | 1 | 2
null | 2 | null | 2
0 | 2 | 4 | null
And a table S:
c | d
1 | 2
2 | 2
3 | 2
null | 2
4 | null
The result that I got from doing
select *
from R natural full outer join S
Was:
a | b | c | d | e
1 | null | 1 | 2 | 2
1 | 3 | null | 2 | 2
2 | 4 | 2 | 2 | 2
null | 5 | 2 | 2 | 2
null | 4 | 1 | 2 | 2
null | 2 | null | 2 | 2
0 | 2 | 4 | null | null
null | null | 3 | 2 | null
However this is not correct because the sum of all the values from the following query has to be 20:
SELECT b, COUNT(*), AVG(a+d)
FROM R NATURAL FULL OUTER JOIN S
WHERE NOT d<>e
GROUP BY b
Please note that this was all done by hand.