Encyclopedia of Database Systems

Living Edition
| Editors: Ling Liu, M. Tamer Özsu

Join

  • Cristina SirangeloEmail author
Living reference work entry
DOI: https://doi.org/10.1007/978-1-4899-7993-3_1260-2

Definition

The join is a binary operator of the relational algebra that combines tuples of different relations based on a relationship between values of their attributes. The primitive version of the join operator is called natural join. Given two relation instances R 1, over set of attributes U 1, and R 2 over set of attributes U 2, the natural join R 1R 2 returns a new relation, over set of attributes U 1U 2, consisting of tuples {t |t(U 1) ∈ R 1 and t(U 2) ∈ R 2}. Here t(U) denotes the restriction of the tuple t to attributes in the set U.

A derivable version of the join operator is obtained by composing the natural join with the selection operator σ: the theta join R 1 θ R 2 is defined as σ θ (R 1R 2), where θ is an arbitrary condition allowed in a generalized selection over set of attributes U 1U 2. In the case that θ is a conjunction of equality atoms of the form A = B, where A is an attribute in U 1 and B an attribute in U 2, the theta join is called equijoin.

Another derivable join operator is the semijoin, denoted by R 1R 2; it is defined as \( {\pi}_{U_1} \)(R 1R 2), where \( {\pi}_{U_1} \) denotes the projection on attributes U 1.

Key Points

In the natural join R 1R 2, tuples of R 1 and R 2 having the same values of common attributes are combined. If the sets of attributes of R 1 and R 2 are disjoint, R 1R 2 coincides with the Cartesian product.

The natural join is often used to combine tuples based on attributes correlated by a foreign key constraint: consider a relation Students over attributes (student-number, student-name), containing tuples {(1001, Black), (1002, White)}, and a relation Exams over attributes (course-number, student-number, grade), containing tuples {(EH1, 1001, A), (EH1, 1002, A), (GH5, 1001, C)}. Then the natural join StudentsExams is a relation over attributes (student-number, student-name, course-number, grade) with tuples {(1001, Black, EH1, A), (1001, Black, GH5, C), (1002, White, EH1, A)}.

In the absence of attribute names, the only primitive notion of join is the Cartesian product. In this case operators of theta join and equijoin can be derived by composing selection and Cartesian product. More precisely, if θ is a Boolean combination of atoms of the form j  α  k with j ≤ arity(R 1) and k ≤ arity(R 2) and α ∈ {=,  ≠, <, >, ≤, ≥}, then the theta join R 1 θ R 2 in the unnamed algebra is defined as σ θ(R 1 × R 2), where θ′ is obtained from θ by replacing each atom j α k with j  α (arity(R 1) + k).

In each of the join operators described above (except the semijoin), there can be tuples of the input relations which do not occur in the output, because they satisfy the join condition with no tuple of the other relation. The left (right) outer join adds to the join of R 1 and R 2 all tuples of R 1 (R 2) not occurring in the join, completed with nulls on attributes of R 2 (R 1). The full outer join adds both tuples of R 1 and R 2 to the join.

Cross-References

Copyright information

© Springer Science+Business Media LLC 2017

Authors and Affiliations

  1. 1.IRIFParis Diderot UniversityParisFrance

Section editors and affiliations

  • Leonid Libkin
    • 1
  1. 1.School of InformaticsUniversity of EdinburghEdinburghUK