r"""Create a SQL JOIN against this :class:`_expression.Select` object's criterion and apply generatively, returning the newly resulting :class:`_expression.Select`. E.g.:: stmt = select(user_table).join( address_table, user_table.c.id ==
(
self,
target: _JoinTargetArgument,
onclause: Optional[_OnClauseArgument] = None,
*,
isouter: bool = False,
full: bool = False,
)
| 5524 | |
| 5525 | @_generative |
| 5526 | def join( |
| 5527 | self, |
| 5528 | target: _JoinTargetArgument, |
| 5529 | onclause: Optional[_OnClauseArgument] = None, |
| 5530 | *, |
| 5531 | isouter: bool = False, |
| 5532 | full: bool = False, |
| 5533 | ) -> Self: |
| 5534 | r"""Create a SQL JOIN against this :class:`_expression.Select` |
| 5535 | object's criterion |
| 5536 | and apply generatively, returning the newly resulting |
| 5537 | :class:`_expression.Select`. |
| 5538 | |
| 5539 | E.g.:: |
| 5540 | |
| 5541 | stmt = select(user_table).join( |
| 5542 | address_table, user_table.c.id == address_table.c.user_id |
| 5543 | ) |
| 5544 | |
| 5545 | The above statement generates SQL similar to: |
| 5546 | |
| 5547 | .. sourcecode:: sql |
| 5548 | |
| 5549 | SELECT user.id, user.name |
| 5550 | FROM user |
| 5551 | JOIN address ON user.id = address.user_id |
| 5552 | |
| 5553 | .. versionchanged:: 1.4 :meth:`_expression.Select.join` now creates |
| 5554 | a :class:`_sql.Join` object between a :class:`_sql.FromClause` |
| 5555 | source that is within the FROM clause of the existing SELECT, |
| 5556 | and a given target :class:`_sql.FromClause`, and then adds |
| 5557 | this :class:`_sql.Join` to the FROM clause of the newly generated |
| 5558 | SELECT statement. This is completely reworked from the behavior |
| 5559 | in 1.3, which would instead create a subquery of the entire |
| 5560 | :class:`_expression.Select` and then join that subquery to the |
| 5561 | target. |
| 5562 | |
| 5563 | This is a **backwards incompatible change** as the previous behavior |
| 5564 | was mostly useless, producing an unnamed subquery rejected by |
| 5565 | most databases in any case. The new behavior is modeled after |
| 5566 | that of the very successful :meth:`_orm.Query.join` method in the |
| 5567 | ORM, in order to support the functionality of :class:`_orm.Query` |
| 5568 | being available by using a :class:`_sql.Select` object with an |
| 5569 | :class:`_orm.Session`. |
| 5570 | |
| 5571 | See the notes for this change at :ref:`change_select_join`. |
| 5572 | |
| 5573 | |
| 5574 | :param target: target table to join towards |
| 5575 | |
| 5576 | :param onclause: ON clause of the join. If omitted, an ON clause |
| 5577 | is generated automatically based on the :class:`_schema.ForeignKey` |
| 5578 | linkages between the two tables, if one can be unambiguously |
| 5579 | determined, otherwise an error is raised. |
| 5580 | |
| 5581 | :param isouter: if True, generate LEFT OUTER join. Same as |
| 5582 | :meth:`_expression.Select.outerjoin`. |
| 5583 |
no outgoing calls
no test coverage detected