I don’t know the specific library you’re using. But I’ll try to answer for relational databases in general.
Suppose you’re joining table L to table R, on a column ‘joinColumn’ that both tables have. The result of that query is a list of rows containing (some of) the columns from L and also (some of) the columns from R.
In all cases, the results will include every combination of rows from L and R which have matching (non-null) values for ‘joinColumn’. The different types of join differ on whether they include unmatched rows too:
-
An inner join (which is usually the default) returns only the matched rows.
-
A left join returns all rows from table L, including any unmatched ones (with NULLs where the values from table R would go).
-
A right join returns all rows from table R, including any unmatched ones (with NULLs where the values from table L would go).
-
An outer join returns all rows from both tables (with NULLs filling in the missing values on either side where they weren’t matched).
A trivial example may help. Suppose we have two tables, with just a couple of rows each:
Table L:
+------+---------+
| keyL | joinCol |
+------+---------+
| 1 | A |
| 2 | B |
+------+---------+
Table R:
+------+---------+
| keyR | joinCol |
+------+---------+
| 10 | A |
| 11 | C |
+------+---------+
Both tables have a row with ‘A’ for joinCol
, so a simple inner join of L to R on joinCol
would give just those:
+---------+------+------+
| joinCol | keyL | keyR |
+---------+------+------+
| A | 1 | 10 |
+---------+------+------+
While a left join would also give the other row from L:
+---------+------+------+
| joinCol | keyL | keyR |
+---------+------+------+
| A | 1 | 10 |
| B | 2 | NULL |
+---------+------+------+
Similarly, a right join would include R’s unmatched row:
+---------+------+------+
| joinCol | keyL | keyR |
+---------+------+------+
| A | 1 | 10 |
| C | NULL | 11 |
+---------+------+------+
And finally, a full outer join would include all of those:
+---------+------+------+
| joinCol | keyL | keyR |
+---------+------+------+
| A | 1 | 10 |
| B | 2 | NULL |
| C | NULL | 11 |
+---------+------+------+
In my experience, inner joins are most common; it’s also fairly common to use left joins to pull in extra info from a lookup table or a parent table which might not include the value you’re looking for. I can’t recall ever using a right join or an outer join, though.