Union (∪) is a set‑oriented relational‑algebra operation that combines tuples from two relations into a single relation. It works exactly like the mathematical union of two sets. In simple terms, the union operation takes two tables with the same structure and returns all distinct rows that appear in either of them.

Union is very useful when you want to merge data from two similar tables, such as results from different departments, temporary tables, or different time periods, without worrying about duplicates.

When Is Union Allowed? (Union Compatibility)

Before applying union, two relations must be union‑compatible, which means:

  • They must have the same number of attributes.

  • The attributes must be in the same order.

  • Corresponding attributes must have compatible domains (for example, both emp_id fields are of type integer, both name fields are of type string, and so on).

If the two relations are not union‑compatible, the union operation is not defined and cannot be performed.

Syntax of Union

The general syntax is:

RSR \cup S
  • RR and SS: the two input relations (tables).

  • The result is a new relation with the same schema as RR and SS, and all distinct tuples that appear in either RR or SS.

Because relational algebra treats relations as sets, duplicate tuples are automatically removed from the result.

Example of Union

Consider two tables storing temporary employee data with the same structure:

  • TEMP_A(emp_id, name, salary)

  • TEMP_B(emp_id, name, salary)

TEMP_A contains:

emp_idnamesalary
101Alice45000
102Bob50000

TEMP_B contains:

emp_idnamesalary
102Bob50000
103Charlie55000

The union:

TEMPATEMPBTEMP_A \cup TEMP_B

Gives a result like:

emp_idnamesalary
101Alice45000
102Bob50000
103Charlie55000

Notice that the row for emp_id 102 appears only once, even though it exists in both tables, because duplicates are removed.

Key Properties of Union

  • Union is commutative:

    RS=SRR \cup S = S \cup R
  • Union is idempotent:

    RR=RR \cup R = R

    because adding the same set again does not change the result.

  • Union only works on union‑compatible relations; otherwise the operation is invalid.

Why Union Matters in DBMS?

  • It allows combining results from different tables or sub‑queries that share the same structure.

  • It corresponds directly to SQL’s UNION operator used to merge query outputs.

  • It helps students understand that relations are sets of tuples, so operations like union behave just like set union in mathematics.