Table of Contents

Class JoinCondition

Namespace
YndigoBlue.Velocity.Model
Assembly
YndigoBlue.Velocity.dll

Represents the ON condition in a SQL JOIN clause that specifies which columns to join on.

public class JoinCondition
Inheritance
JoinCondition

Examples

Simple equality join (most common):

// JOIN users ON orders.user_id = users.id
JoinCondition joinCondition = new JoinCondition(
    ordersTable["user_id"],
    usersTable["id"]
);

Join join = new Join(ordersTable, usersTable, joinCondition, JoinType.Inner);

Query query = new Query();
query.AddFromItem(join);
query.AddSelectItem(ordersTable["order_date"]);
query.AddSelectItem(usersTable["username"]);

// SQL: SELECT orders.order_date, users.username
//      FROM orders
//      INNER JOIN users ON orders.user_id = users.id

Explicit equality join:

// Same as above but with explicit operator
JoinCondition joinCondition = new JoinCondition(
    ordersTable["user_id"],
    JoinOperatorType.Equals,
    usersTable["id"]
);

Join join = new Join(ordersTable, usersTable, joinCondition, JoinType.Inner);

Non-equality join:

// Find orders with prices higher than the product's base price
// JOIN products ON orders.price > products.base_price
JoinCondition joinCondition = new JoinCondition(
    ordersTable["price"],
    JoinOperatorType.GreaterThan,
    productsTable["base_price"]
);

Join join = new Join(ordersTable, productsTable, joinCondition, JoinType.Inner);

// SQL: FROM orders
//      INNER JOIN products ON orders.price > products.base_price

Multiple joins with different conditions:

// First join: orders with users
JoinCondition userJoin = new JoinCondition(
    ordersTable["user_id"],
    usersTable["id"]
);

Join firstJoin = new Join(ordersTable, usersTable, userJoin, JoinType.Inner);

// Second join: add addresses
JoinCondition addressJoin = new JoinCondition(
    usersTable["address_id"],
    addressesTable["id"]
);

Join secondJoin = new Join(firstJoin, addressesTable, addressJoin, JoinType.Left);

Query query = new Query();
query.AddFromItem(secondJoin);

// SQL: FROM orders
//      INNER JOIN users ON orders.user_id = users.id
//      LEFT JOIN addresses ON users.address_id = addresses.id

Remarks

JoinCondition defines the relationship between two tables in a JOIN operation. It specifies which columns from each table should be compared and what comparison operator to use.

While equality (=) is by far the most common join operator, Velocity also supports other comparison operators like >, <, >=, <=, and <> for advanced join scenarios.

Constructors

JoinCondition(ISelectItem, JoinOperatorType, ISelectItem)

Creates a new join condition with a specified comparison operator.

JoinCondition(ISelectItem, ISelectItem)

Creates a new join condition using equality comparison (most common).

Properties

FirstSelectItem

Gets the column from the left table in the join comparison.

JoinOperatorType

Gets the comparison operator used in the join condition (=, >, <, etc.).

SecondSelectItem

Gets the column from the right table in the join comparison.