Detailed Notes on Selection Operation in Relational Algebra
Selection Operation in Relational Algebra
Your comprehensive guide to understanding the selection operation, its syntax, properties, and applications.
Introduction
The Selection operation (denoted by σ
) is a fundamental operation in relational algebra. It allows filtering of rows (or tuples) from a table based on specified conditions, resulting in horizontal partitioning.
Syntax of Selection
The general syntax for the selection operation is:
σ(condition)(Relation)
Conditions can include:
- Comparisons with constants (e.g.,
salary > 50000
). - Comparisons between attributes (e.g.,
dept_id = manager_id
). - Boolean Connectives (e.g., AND, OR).
Key Characteristics
- Horizontal Partitioning: Filters rows while preserving all columns.
- Commutativity: The order of conditions does not affect the final result.
- Combining Conditions: Multiple conditions can be combined using Boolean operators.
Examples
Example 1: Basic Selection
Given the Employee table:
emp_id | name | dept_id | salary 101 | Alice | 1 | 12000 102 | Bob | 3 | 15000 103 | Carol | 2 | 10000
Query: Select all employees in department 3.
σ(dept_id = 3)(Employee)
Result:
emp_id | name | dept_id | salary 102 | Bob | 3 | 15000
Example 2: Combining Conditions
Query: Select employees in department 1 with a salary greater than 10,000.
σ(dept_id = 1 ∧ salary > 10000)(Employee)
Result:
emp_id | name | dept_id | salary 101 | Alice | 1 | 12000
Advanced Concepts
Nested Selection
Due to commutativity, conditions can be applied in any order. For example:
- Step 1: Apply
salary > 10000
. - Step 2: Apply
dept_id = 1
.
Attribute Comparison
Conditions can also compare attributes within the same tuple. For example:
σ(emp_id > dept_id)(Employee)
Applications
The selection operation is fundamental to SQL and forms the basis for query optimization in relational databases. It is essential for competitive exams like GATE and UGC NET.