Informatics Practices · Ch 1 — Querying and SQL Functions
Operations on Relations
Operations on Relations
Operations on relations let us combine or compare data from two tables. The textbook introduces three such operations: Union, Intersection, and Set Difference. Each of these is a binary operation — it works on two tables at a time.
These operations can be applied only when both tables have the same number of attributes, and the corresponding attributes in both tables share the same domain (data type and allowed values). In other words, the two tables must be union-compatible.
Here is what each operation does:
- Union – Combines all distinct tuples from both tables. If a tuple appears in either table, it appears once in the result.
- Intersection – Returns only those tuples that are present in both tables. A tuple must exist in both to appear in the result.
- Set Difference – Returns tuples that are in the first table but not in the second. The order matters:
Table1 – Table2is different fromTable2 – Table1.
These operations are directly borrowed from set theory in mathematics. They help in tasks like finding common customers across two databases, merging records from two branches, or identifying records missing from one table compared to another. …