GATE CSEIT/Database Relational algebra part 1 ( Selection and projection operator).
Relational algebra is a foundational aspect of database query languages, providing a formal framework for manipulating and retrieving data from relational databases. Two fundamental unary operations in relational algebra are selection and projection.
Selection Operator (σ):
The selection operator filters rows (tuples) from a relation based on a specified predicate. It retrieves only those tuples that satisfy the given condition, effectively performing a horizontal partitioning of the relation. The general form of the selection operation is:
σcondition(R)\sigma_{\text{condition}}(R)
Here, RR represents the relation, and the condition is a predicate applied to each tuple. For example, to select employees with a salary greater than 50,000 from an ‘Employee’ relation:
σsalary>50000(Employee)\sigma_{\text{salary} > 50000}(\text{Employee})
This operation will yield a relation containing only those employees whose salary exceeds 50,000.
Projection Operator (π):
The projection operator extracts specific columns (attributes) from a relation, effectively performing a vertical partitioning. It removes duplicate rows in the result, ensuring that the output is a set of unique tuples. The general form of the projection operation is:
πattribute1,attribute2,…,attributeN(R)\pi_{\text{attribute1}, \text{attribute2}, \ldots, \text{attributeN}}(R)
For example, to retrieve only the names and departments of all employees from an ‘Employee’ relation:
πname,department(Employee)\pi_{\text{name}, \text{department}}(\text{Employee})
This operation will produce a relation containing unique combinations of employee names and their corresponding departments.
Key Differences:
- Selection (σ): Operates on rows, filtering tuples based on a condition.
- Projection (π): Operates on columns, extracting specified attributes and removing duplicates.
Example:
Consider a ‘Student’ relation with attributes (StudentID, Name, Age, Major):
StudentID | Name | Age | Major |
---|---|---|---|
1 | Alice | 20 | ComputerSci |
2 | Bob | 22 | Math |
3 | Charlie | 20 | Physics |
4 | David | 23 | ComputerSci |
-
Selection: To find students aged 20:
σAge=20(Student)\sigma_{\text{Age} = 20}(\text{Student})
Result:
StudentID Name Age Major 1 Alice 20 ComputerSci 3 Charlie 20 Physics -
Projection: To list all unique majors:
πMajor(Student)\pi_{\text{Major}}(\text{Student})
Result:
Major ComputerSci Math Physics
Understanding these operators is crucial for formulating queries in relational databases and is a significant component of database management systems, especially in the context of GATE Computer Science examinations.
For a visual explanation and further examples of selection and projection operations in relational algebra, you might find the following video helpful:
Contents
- 0.1 GATE CSEIT/Database Relational algebra part 1 ( Selection and projection operator).
- 0.2 Module 2 Relational Algebra 25-08-2025 Prepared by
- 0.3 3. Relational Model and Relational Algebra
- 1 Relational Algebra – Part 1: Selection & Projection
- 2 GATE-Level Practice Question
- 3 Extra Tip for GATE:
- 4 Want More?
GATE CSEIT/Database Relational algebra part 1 ( Selection and projection operator).
Module 2 Relational Algebra 25-08-2025 Prepared by
3. Relational Model and Relational Algebra
Here’s a simple and GATE-focused explanation of Relational Algebra – Part 1 covering the Selection (σ) and Projection (π) operators — essential for GATE CSE/IT Database (DBMS) preparation.
Relational Algebra – Part 1: Selection & Projection
Relational Algebra is a procedural query language in DBMS used to retrieve data from relational databases using set-based operations.
1. Selection Operator (σ)
Syntax:
Meaning:
It selects rows (tuples) from the table (relation) that satisfy a given condition.
Example:
Let’s say the relation Student
is:
Roll | Name | Marks |
---|---|---|
1 | Aman | 85 |
2 | Riya | 75 |
3 | John | 90 |
Query:
Roll | Name | Marks |
---|---|---|
1 | Aman | 85 |
3 | John | 90 |
2. Projection Operator (π)
Syntax:
Meaning:
It selects columns (attributes) from the table.
Example:
Using the same Student
relation.
Query:
Name | Marks |
---|---|
Aman | 85 |
Riya | 75 |
John | 90 |
Key Differences:
Feature | Selection (σ) | Projection (π) |
---|---|---|
Works on | Rows (tuples) | Columns (attributes) |
Purpose | Filter data using conditions | Select specific columns |
Removes | Rows that don’t satisfy condition | Columns not listed |
Duplicate rows | Not affected | May remove duplicates |
Combined Example:
Query:
-
First apply:
σ Marks > 80 (Student)
→ Gives rows with Marks > 80 -
Then apply:
π Name
→ Gives onlyName
column of those rows
Final Output:
Name |
---|
Aman |
John |
GATE-Level Practice Question
Q: Consider relation Employee(EID, Name, Salary, Dept)
.
What does the following expression return?
A) Names of all employees
B) Names of HR employees with salary > 30000
C) Employees with salary < 30000
D) Names and salaries of HR employees
Extra Tip for GATE:
-
These operations are building blocks for complex relational queries.
-
Practice query simplification and output prediction.
-
Often asked in 1-mark or 2-mark MCQs with outputs.
Want More?
Would you like:
-
Diagrams for these operators? -
PDF notes or quiz set? -
Short video (Hindi/English) explanation?
Let me know and I’ll send it your way!