![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Basic Operators in Relational Algebra
Relational Algebra is a procedural query language, it is used to provide a single table / relation as output of performing operations on more than one relations. Some of the basic relations will be discussed here.
In our course of learning, we will use three relations (table) −
Table 1: course
Course_id | Name |
---|---|
1 | Computer science |
2 | Information Technology |
3 | mechanical |
Table 2: students
Roll No. | Name | address | age |
---|---|---|---|
1 | Ram | Delhi | 18 |
2 | Raju | hyderabad | 20 |
4 | Faiz | Delhi | 22 |
5 | Salman | hyderabad | 20 |
Table 3: Hostel
St. No. | Name | address | age |
---|---|---|---|
1 | Ram | Delhi | 18 |
2 | Akash | hyderabad | 20 |
3 | neha | Jhansi | 21 |
On this relations, we will perform some operation to make new relation based on operations performed.
Selection operation (σ) − The selection operator denoted by sigma σ is used to select the tuples of a relation based on some condition. Only those tuples that fall under certain conditions are selected.
Syntax
σ(condition)(relation_name)
Example
Select the student with course id 1. σ(course_id = 1)(student)
Result
Roll No. | Name | address | age |
---|---|---|---|
4 | Faiz | Delhi | 22 |
Projection operation (∏) The projection operator denoted by ∏ is used to select columns from a specific reaction. Only specific columns are selected.
Syntax
∏(column1 , column2 , … , columnn)(relation_name)
Example
Let’s select all students's name and no who are in hostel. ∏( st. No. , name)(hostel)
Result
St. No. | Name |
---|---|
1 | Ram |
2 | Akash |
3 | neha |
The row are always distinct in projection i.e. if their is any other student whose name is panjak the other one is removed.
Cross Product(X) - Cross product is denoted using the X symbol and is used to find the value of join of two variables. In cross product each tuple of relation1 is crossed with each tuple of relation2. Which makes the output relation of the order nXm, where n is the number of tuples in relation1 and m is the number of tuples in relation2.
Syntax
relation1 X relation2
Example
Let’s find cross product of course and hostel table.
student X course
St. No. | Name | address | age | Course_id | Name |
---|---|---|---|---|---|
1 | Ram | Delhi | 18 | 1 | Computer science |
1 | Ram | Delhi | 18 | 2 | Information Technology |
1 | Ram | Delhi | 18 | 3 | mechanical |
2 | Akash | hyderabad | 20 | 1 | Computer science |
2 | Akash | hyderabad | 20 | 2 | Information Technology |
2 | Akash | hyderabad | 20 | 3 | mechanical |
3 | neha | Jhansi | 21 | 1 | Computer science |
3 | neha | Jhansi | 21 | 2 | Information Technology |
3 | neha | Jhansi | 21 | 3 | mechanical |
Union (U) - The union of two relations relation1 and relation2 will gives the tuples that are either in relation1 or in relation2 but tuples that are in both relation1 and relation2 are considered only once.
Also both relations should be of the same domain for finding there union.
Syntax
relation1 U relation2
Example
Let’s find the union of student and hostel
student U hostel
Roll No. | Name | address | age |
---|---|---|---|
1 | Ram | Delhi | 18 |
2 | Raju | hyderabad | 20 |
4 | Faiz | Delhi | 22 |
5 | Salman | hyderabad | 20 |
2 | Akash | hyderabad | 20 |
3 | neha | Jhansi | 21 |
Minus (-) operator - operator is denoted by - symbol. Relation1 - relation2 will result into a relation in which the tuple in relation1 and not in relation2 are present. For calculating minus too, the relations must be union compatible.
Syntax
relation1 - relation2
Example
Let’s find the operation student - hostel
student - hostel
Roll No. | Name | address | age |
---|---|---|---|
2 | Raju | hyderabad | 20 |
4 | Faiz | Delhi | 22 |
5 | Salman | hyderabad | 20 |
rename(ρ) − the rename operation denoted by the ρ is used to rename the given relation to another name given.
Syntax
ρ(new_name , old_name)