Join

The Join class represents a SQL JOIN clause. It allows specifying the join type, the table to join, and the join condition.

Constants

Methods

inner($table, $condition, $alias, $schema)

Static factory method to create an INNER JOIN.

Example:

use Staple\Query\Join;

$join = Join::inner('profiles', 'users.id = profiles.user_id', 'p');
// Result: INNER JOIN profiles p ON users.id = profiles.user_id

left($table, $condition, $alias, $schema)

Static factory method to create a LEFT OUTER JOIN.

Example:

use Staple\Query\Join;

$join = Join::left('logs', 'users.id = logs.user_id');

setTable($table)

Sets the table to be joined.

setCondition($condition)

Sets the ON condition for the join.

setTableAlias($alias)

Sets an alias for the joined table.

build()

Builds and returns the SQL fragment for the join.

Example:

$join = new Join(Join::RIGHT, 'orders', 'users.id = orders.user_id');
echo $join->build();
// Result: RIGHT OUTER JOIN orders ON users.id = orders.user_id