Making a query with an inner join

With an inner join, items from the primary table or entity on the left are joined to items from the table or entity on the right, based on matching values. If a primary item on the left has no matching value on the right, that primary item is not included in the result. A foreign key from one side to the other is the basis of matching.

In SQL, it generally does not matter which side of the join provides the foreign key nor whether the foreign key is defined in metadata. All that matters is for one side of the join to have a column or property with values that match values in the column of another table or property.

The query builder API uses different signatures on the join method depending on which side of a join provides the foreign key.

  • join(primaryEntity#column) – Joins two entities that have the foreign key is on left
  • join(secondaryEntity#column) – Joins two entities that have the foreign key is on the right.
  • join("columnPrimary", table, "columnDependent") – Joins two entities without regard to foreign keys.