The Wayback Machine - https://web.archive.org/web/20240724235921/https://www.geeksforgeeks.org/select-operation-in-relational-algebra/
Open In App

SELECT Operation in Relational Algebra

Last Updated : 26 Jun, 2024
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report

Prerequisite – Relational Algebra 

Select operation chooses the subset of tuples from the relation that satisfies the given condition mentioned in the syntax of selection. The selection operation is also known as horizontal partitioning since it partitions the table or relation horizontally. 

Notation:

σ c(R)

where ‘c’ is the selection condition which is a boolean expression(condition), we can have a single condition like Roll= 3 or a combination of conditions like X>2 AND Y<1, and symbol ‘σ (sigma)’ is used to denote select(choose) operator,

R is a relational algebra expression, whose result is a relation. The boolean expression specified in condition ‘c’ can be written in the following form:

<attribute name> <comparison operator> <constant value> or <attribute name>

where <attribute name> is the name of an attribute of relation, <comparison operator> is any of the operator {<, >, =, <=, >=, !=} and, <constant value> is a constant value taken from the domain of the relation.  

Example-1:

σ Place = 'Mumbai' or Salary >= 1000000 (Citizen)
σ Department = 'Analytics'(σLocation = 'NewYork'(Manager))

The query above(immediate) is called nested expression, here, as usual, we evaluate the inner expression first (which results in relation say Manager1), then we calculate the outer expression on Manager1(the relation we obtained from evaluating the inner expression), which results in relation again, which is an instance of a relation we input.

Example-2:

Given a relation Student(Roll, Name, Department, Fees, Team) with the following tuples:

Roll Name Department Fees Team
1 Bikash CSE 22000 A
2 Josh CSE 34000 A
3 Kevin ECE 36000 C
4 Ben ECE 56000 D

Select all the students of Team A :

σ Team = 'A' (Student)
Roll Name Department Fees Team
1 Bikash CSE 22000 A
2 Josh CSE 34000 A

Select all the students of department ECE whose fees are greater than and equal to 10000 and belong to a Team other than A.

σ σ Department = 'ECE' and Fees >= 10000(σTeam != 'A' (Student))
Roll Name Department Fees Team
3 Kevin ECE 36000 C
4 Ben ECE 56000 D

Important points about Select operationThe select: Select operator is Unary, which means it is applied to a single relation only. The selection operation is commutative that is,

σ c1(σ c2(R)) = σ c2(σ c1(R))

The degree (number of attributes) of the resulting relation from a Selection operation is the same as the degree of the Relation given. The cardinality (number of tuples) of the resulting relation from a Selection operation is,

0 <= σ c (R) <= |R|

Similar Reads

Difference between Relational Algebra and Relational Calculus
Both Relational Algebra and Relational Calculus are formal query languages. Relational Algebra: Relational Algebra is a procedural language. In Relational Algebra, The order is specified in which the operations have to be performed. In Relational Algebra, frameworks are created to implement the queries. The basic operation included in relational al
3 min read
PROJECT Operation in Relational Algebra
Prerequisite - Relational Algebra Project operation selects (or chooses) certain attributes discarding other attributes. The Project operation is also known as vertical partitioning since it partitions the relation or table vertically discarding other columns or attributes. Notation: &pi;A(R) where 'A' is the attribute list, it is the desired set o
2 min read
Cartesian Product Operation in Relational Algebra
Prerequisite - Relational Algebra We already are aware of the fact that relations are nothing but a set of tuples, and here we will have 2 sets of tuples. On applying CARTESIAN PRODUCT on two relations that is on two sets of tuples, it will take every tuple one by one from the left set(relation) and will pair it up with all the tuples in the right
3 min read
RENAME (&rho;) Operation in Relational Algebra
Prerequisites - Introduction of Relational Algebra in DBMS, Basic Operators in Relational Algebra The RENAME operation is used to rename the output of a relation. Sometimes it is simple and suitable to break a complicated sequence of operations and rename it as a relation with different names. Reasons to rename a relation can be many, like - We may
2 min read
Difference between Tuple Relational Calculus (TRC) and Domain Relational Calculus (DRC)
1. Tuple Relational Calculus (TRC) : A tuple relational calculus is a non-procedural query language that specifies to select of the tuples in a relation. It can select the tuples with a range of values or tuples for certain attribute values etc. The resulting relation can have one or more tuples. Notation : {T | P (T)} or {T | Condition (T)} where
3 min read
Introduction of Relational Algebra in DBMS
Pre-Requisite: Relational Model in DBMS Relational Algebra is a procedural query language. Relational algebra mainly provides a theoretical foundation for relational databases and SQL. The main purpose of using Relational Algebra is to define operators that transform one or more input relations into an output relation. Given that these operators ac
4 min read
Example Queries on Relational Algebra
Given below are a few examples of a database and a few queries based on that. (1). Suppose there is a banking database which comprises following tables : Customer(Cust_name, Cust_street, Cust_city) Branch(Branch_name, Branch_city, Assets) Account (Branch_name, Account_number, Balance) Loan(Branch_name, Loan_number, Amount) Depositor(Cust_name, Acco
1 min read
Set Difference Operator in Relational Algebra
Relational Algebra is used to play with the data stored in relational databases. Relational Algebra has many operations to play with tables. One of the fundamental operations is set difference. This article will discuss Set Difference, its condition, and its examples. Key Terms Used in Set Difference Operator Relation- In Relational Algebra 'Table'
4 min read
Basic Operators in Relational Algebra
Basics of Relational model: Relational Model Relational Algebra is a procedural query language that takes relations as an input and returns relations as an output. There are some basic operators which can be applied in relation to producing the required results which we will discuss one by one. We will use STUDENT_SPORTS, EMPLOYEE, and STUDENT rela
3 min read
How to solve Relational Algebra problems for GATE
In this article, Let's discuss common types of questions in relational algebra which are asked in GATE. Before reading this article, you should have an idea about Basic Operators and Extended Operators in relational algebra. Type-1: Given a relational algebra expression, find the result. Suppose you have a relation Order(Prod_Id, Agent_Id, Order_Mo
5 min read
three90RightbarBannerImg