| layout | api-command | ||||||
|---|---|---|---|---|---|---|---|
| language | Java | ||||||
| permalink | api/java/inner_join/ | ||||||
| command | innerJoin | ||||||
| related_commands |
|
{% apibody %} sequence.innerJoin(otherSequence, predicate_function) → stream array.innerJoin(otherSequence, predicate_function) → array {% endapibody %}
Returns an inner join of two sequences.
The returned sequence represents an intersection of the left-hand sequence and the right-hand sequence: each row of the left-hand sequence will be compared with each row of the right-hand sequence to find all pairs of rows which satisfy the predicate. Each matched pair of rows of both sequences are combined into a result row. In most cases, you will want to follow the join with zip to combine the left and right results.
{% infobox %}
Note that innerJoin is slower and much less efficient than using eqJoin or concatMap with getAll. You should avoid using innerJoin in commands when possible.
{% endinfobox %}
Example: Return a list of all matchups between Marvel and DC heroes in which the DC hero could beat the Marvel hero in a fight.
r.table("marvel").innerJoin(r.table("dc"),
(marvel_row, dc_row) -> marvel_row.g("strength").lt(dc_row.g("strength"))
).zip().run(conn);(Compare this to an outerJoin with the same inputs and predicate, which would return a list of all Marvel heroes along with any DC heroes with a higher strength.)