Projection in SQL (Relational Algebra Concepts)
Notes: Selection in SQL and Relational Algebra
Selection in SQL (Relational Algebra Concepts)
What is Selection?
In Relational Algebra, Selection is an operation used to pick specific rows (tuples) from a table based on a
condition.
It filters the table and returns only the rows that match the condition.
Symbol: sigma
Example (Relational Algebra)
Given a table STUDENT(id, name, age, course)
To get students older than 20, we write:
sigma age > 20 (STUDENT)
This means: Select rows where age is greater than 20.
Equivalent SQL Query:
SELECT * FROM STUDENT WHERE age > 20;
Key Features of Selection:
- Works on: Rows (not columns)
- Keeps: All columns, only selected rows
- Condition Used: Yes (filtering using WHERE)
- SQL Equivalent: SELECT * FROM table WHERE condition
- Output: A new table (relation) with filtered rows only
Example Table: STUDENT
| id | name | age | course |
|----|-------|-----|--------|
| 1 | Ali | 20 | CSE |
Projection in SQL (Relational Algebra Concepts)
| 2 | Sara | 21 | EEE |
| 3 | Rani | 22 | ME |
| 4 | Sara | 21 | EEE |
Relational Algebra Query:
sigma age > 20 (STUDENT)
Result:
| id | name | age | course |
|----|-------|-----|--------|
| 2 | Sara | 21 | EEE |
| 3 | Rani | 22 | ME |
| 4 | Sara | 21 | EEE |
Summary:
- Selection = Pick Rows
- Symbol = sigma
- SQL uses WHERE clause
- Keeps all columns but filters rows