PB

3.5

Joins in SQL

  • Joins are used to combine records from two or more tables in a database.

Types of Joins

  • Equijoins: The most common type of join where the columns being compared have equal values.

  • Non-equijoins: These joins compare columns with an operator other than equality (e.g., greater than, less than).

Column Comparisons

  • Joins can involve any columns of a table as long as the columns have comparable data types.

  • When dealing with foreign keys, the referenced primary key must be from the same table in a self-join.

  • Aliases are commonly used in joins to distinguish between the left and right tables.

CROSS JOINs

  • A CROSS JOIN clause is used when comparing columns without a specific condition.

  • This produces all possible combinations of rows from both tables, leading to a Cartesian product.

  • A CROSS JOIN typically requires an ON clause to specify the nature of the relationship being examined.