Difference between Selection and Projection in DBMS (original) (raw)
Last Updated : 29 Sep, 2024
Selection and projection are two major basic model operations that are used when processing queries in DBMS. Although both are associated with the operation of a database, it is used in different capacities. Selection operates by fishing out rows containing values that meet certain criteria while projection operates by fishing out certain columns of a table. It is important to know the difference between these two so as to refine queries and manipulate data in the most efficient way.
**What is Selection in DBMS?
In DBMS, selection is an operation that allows the system to pick rows out of a table as indicated by a certain condition. The condition operates like a lens to pull out only the required columns and here it filters out all the rows which do not meet this condition.
**Notation -
σc (R)
Here, 'c' is the selection condition, and 'σ (sigma)' is used to denote
Example Table: Employees
EmployeeID | Name | Department | Salary |
---|---|---|---|
1 | Alice | HR | 60000 |
2 | Bob | IT | 70000 |
3 | Charlie | IT | 75000 |
4 | David | HR | 62000 |
5 | Eva | Finance | 80000 |
Selection Query
**The following query selects employees who work in the IT department:
Relational Algebra: σDepartment='IT' (Employees) SQL Query : SELECT * FROM Employees WHERE Department = 'IT';
Result
EmployeeID | Name | Department | Salary |
---|---|---|---|
2 | Bob | IT | 70000 |
3 | Charlie | IT | 75000 |
**What is Projection?
This operation selects certain required attributes, while discarding other attributes. Projection in DBMS is a process of selecting some specific attribute/columns from a table while excluding the other attributes/columns from a selected table. It is useful for selecting a set of required attributes of the data.
**Notation -
πA (R)
where 'A' is the attribute list, it is the desired set of attributes from the attributes of relation(R), symbol 'π(pi)' is used to denote the Project operator, R is generally a relational algebra expression, which results in a relation.
Projection Query
**The following query retrieves only the Name and Salary columns from the Employees table:
Relation Algebra: πName Salary (Employees) SQL Query : SELECT Name, Salary FROM Employees;
Result
Name | Salary |
---|---|
Alice | 60000 |
Bob | 70000 |
Charlie | 75000 |
David | 62000 |
Eva | 80000 |
**Difference Between Selection and Projection in DBMS
Category | Selection | Projection |
---|---|---|
Other Names | The selection operation is also known as horizontal partitioning. | The Project operation is also known as vertical partitioning. |
Use | It is used to choose the subset of tuples from the relation that satisfies the given condition mentioned in the syntax of selection. | It is used to select certain required attributes, while discarding other attributes. |
Partitioning | It partitions the table horizontally. | It partitions the table vertically. |
Which used first | The selection operation is performed before projection (if they are to be used together). | The projection operation is performed after selection (if they are to be used together). |
Operator Used | Select operator is used in Selection Operation. | Project operator is used in Projection Operation. |
Operator Symbol | Select operator is denoted by Sigma symbol. | Project operator is denoted by Pi symbol. |
Commutative | Selection is commutative. | Projection is not commutative. |
Column Selection | Select is used to select all columns of a specific tuple. | Project is used to select specific columns. |
SQL Statements used | SELECT, FROM, WHERE | SELECT, FROM |
Conclusion
Selection and projection are two major options that are performed in DBMS, though these two are different from each other. There are two types of operations, selection that is used to filter rows in a table according to some conditions specified and projection that is used to transform rows in a table by selecting columns from it. Either of these operations can be used based on the query requirements and by doing so, overhead of data processing can be minimized.