Unary Relational Operations
Unary Relational Operations
SELECT, PROJECT, and RENAME
-
SELECT (σ) – filters rows (tuples)
-
PROJECT (π) – filters columns (attributes)
An additional supporting operation, RENAME (ρ), is used to rename relations or attributes, especially when combining multiple operations.
1. The SELECT Operation (σ)
Purpose of SELECT
The SELECT operation is used to choose a subset of tuples from a relation that satisfy a specified condition.
-
It filters rows, not columns
-
The structure (attributes) of the relation remains unchanged
-
Only tuples that satisfy the condition appear in the result
📌 SELECT can be viewed as:
-
A filter
-
A restriction
-
A horizontal partition of a relation
Notation
Where:
-
σ (sigma) denotes SELECT
-
R is a relation (or relational algebra expression)
-
Selection condition is a Boolean expression
Example
Select employees who work in department 4:
Select employees whose salary is greater than 30,000:
Selection Conditions
A selection condition consists of one or more clauses of the form:
-
attribute comparison_operator constant -
attribute comparison_operator attribute
Valid comparison operators include:
Clauses can be combined using Boolean operators:
-
AND
-
OR
-
NOT
Complex Condition Example
Retrieve employees who:
-
Work in department 4 and earn more than 25,000
OR -
Work in department 5 and earn more than 30,000
How SELECT Works (Tuple-by-Tuple)
-
The condition is evaluated independently for each tuple
-
Attribute values in the tuple are substituted into the condition
-
If the condition evaluates to TRUE, the tuple is selected
Properties of SELECT
-
Unary operation (applies to one relation)
-
Does not change attributes
-
Number of tuples in result ≤ number of tuples in original relation
-
The fraction of selected tuples is called selectivity
-
Commutative:
-
Multiple SELECTs can be combined into a single SELECT using AND
SELECT vs SQL
Relational Algebra:
Equivalent SQL:
⚠️ Important:
Relational algebra SELECT ≠ SQL SELECT clause
-
Algebra SELECT → selects rows
-
SQL SELECT → selects columns
2. The PROJECT Operation (π)
Purpose of PROJECT
The PROJECT operation selects specific attributes (columns) from a relation.
-
It filters columns, not rows
-
It eliminates duplicate tuples
-
It produces a vertical partition of the relation
Notation
Where:
-
π (pi) denotes PROJECT
-
Attribute list specifies required attributes
Example
Retrieve employee last name, first name, and salary:
Duplicate Elimination
If projected attributes do not include a key, duplicate tuples may arise.
PROJECT automatically removes duplicates to maintain the set property of relations.
Example:
If multiple employees share the same sex and salary, only one tuple appears in the result.
Properties of PROJECT
-
Unary operation
-
Reduces number of attributes
-
Number of tuples in result ≤ number of tuples in original relation
-
Result contains distinct tuples only
-
If projection includes a key, no tuples are lost
-
Not commutative
-
Cascaded projections simplify to a single projection:
PROJECT vs SQL
Relational Algebra:
Equivalent SQL:
Without DISTINCT, SQL allows duplicates—this is not allowed in formal relational algebra.
3. Sequences of Operations
Most database queries require multiple relational algebra operations.
Inline Expression
Retrieve first name, last name, and salary of employees in department 5:
Using Intermediate Relations
This approach:
-
Improves readability
-
Helps in understanding complex queries
-
Allows attribute renaming
4. The RENAME Operation (ρ)
Purpose of RENAME
The RENAME operation is used to:
-
Rename a relation
-
Rename its attributes
-
Or both
This is especially useful in JOINs, UNIONs, and self-referencing queries.
Notation
Other forms:
-
Rename relation only:
-
Rename attributes only:
Example
RENAME vs SQL
In SQL, renaming is done using aliases:
Summary of Unary Operations
| Operation | Symbol | Purpose | Affects |
|---|---|---|---|
| SELECT | σ | Filters tuples | Rows |
| PROJECT | π | Selects attributes | Columns |
| RENAME | ρ | Renames relations/attributes | Names only |


Comments
Post a Comment