DIZNR INTERNATIONAL

GATE CSEIT/Database Relational algebra part 1 ( Selection and projection operator).

GATE CSEIT/Database Relational algebra part 1 ( Selection and projection operator).

https://www.gyanodhan.com/video/7B6.%20GATE%20CSEIT/Database/650.%20Relational%20algebra%20part%201%20%28%20Selection%20and%20projection%20operator%29.mp4

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:

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

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:

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:

php-template
σ<condition>(Relation)

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:

scss
σ Marks > 80 (Student)

Output:

Roll Name Marks
1 Aman 85
3 John 90

It filters rows based on the given condition.


2. Projection Operator (π)

Syntax:

php-template
π<attribute list>(Relation)

Meaning:

It selects columns (attributes) from the table.

Example:

Using the same Student relation.

Query:

scss
π Name, Marks (Student)

Output:

Name Marks
Aman 85
Riya 75
John 90

It removes unwanted columns and may remove duplicates.


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:

css
π Name (σ Marks > 80 (Student))

Step-by-step:

  • First apply: σ Marks > 80 (Student)
    → Gives rows with Marks > 80

  • Then apply: π Name
    → Gives only Name 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?

pgsql
π Name (σ Dept = 'HR' ∧ Salary > 30000 (Employee))

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!

GATE CSEIT/Database Relational algebra part 1 ( Selection and projection operator).

Relational algebra operators – projection