gvwilson / sql-tutorial

The Querynomicon: An Introduction to SQL for Wary Data Scientists
https://gvwilson.github.io/sql-tutorial/
Other
419 stars 35 forks source link

Example 31 statement about full outer joins being the same as cross joins is incorrect #31

Closed cpcloud closed 5 months ago

cpcloud commented 5 months ago

Full outer joins and cross joins are not equivalent.

The cross join of two tables is the Cartesian product of their rows, which means for an empty table on either side, the result will be an empty relation.

For full outer join, which is equivalent to the union of a left outer join and right outer join, an empty table on one side doesn't imply an empty result:

sqlite> .header on
sqlite> .mode markdown
sqlite> create table t (x int);
sqlite> insert into t values (1), (2);
sqlite> create table s (y int);
sqlite> select * from t cross join s;
sqlite> select * from t full outer join s;
| x | y |
|---|---|
| 1 |   |
| 2 |   |