# DBMS | Basic Operators in Relational Algebra

Basic operators in relational algebra: Here, we are going to learn about the basic operators with the examples in Relational Algebra.
Submitted by Anushree Goswami, on June 23, 2019

There are 5 different types of Basic Operators in Relational Algebra in DBMS,

### 1) Selection

Selection operator operates on the rows from a relation. It is denoted by the symbol 'σ'. It is used to manipulate the data in single relation.

For e.g. – Find the information about the students whose marks are above 90.

Name RollNo Marks
Ashish 1 87
Shubham 2 99
Vishakha 3 94
Yash 4 88

σMarks>90(S)

Name RollNo Marks
Shubham 2 99
Vishakha 3 94

### 2) Projection

Projection operator operates on the columns of the relation. It is denoted by the symbol 'π'. It is used to manipulate the data in single relation. It is used to project the column.

For e.g. – From the previous table, only show the columns that contain the Roll No as well as Marks of the Students.

Name RollNo Marks
Ashish 1 87
Shubham 2 99
Vishakha 3 94
Yash 4 88

πRollNo,Marks(S2)

RollNo Marks
1 87
2 99
3 94
4 88

Further, we will discuss the basic operators that are the set operations and used to perform the standard operations on the set in relational algebra. Let us consider two tables A and B.

A –

RollNo Name Marks
1 Aashi 98
3 Anjali 79
4 Brijesh 88

B –

RollNo Name Marks
1 Aashi 98
2 Abhishek 87
3 Anjali 79
4 Brijesh 88

### 3) Union

Union works on the relation as 'either this or that'. In relational algebra, A∪B returns a relation instance that contains the tuples of either relation instance A or relation instance B (or both). Here, A and B need to be union-compatible, and the schema of both result and A must be identical.

Syntax:

```    SELECT * FROM A UNION SELECT * FROM B;
```
RollNo Name Marks
1 Aashi 98
2 Abhishek 87
3 Anjali 79
4 Brijesh 88

### 4) Set Difference

The set difference works on the relation as 'this but not that'. In relational algebra, A - B returns a relation instance that contains the tuples that occur in relation instance A but not in relation instance B. Here, A and B need to be union-compatible, and the schema of both result and A must be identical.

Syntax:

```    SELECT * FROM B MINUS SELECT * FROM A;
```
RollNo Name Marks
2 Abhishek 87

### 5) Cross-product

In relational algebra, Cross-product operation is also referred to as Cartesian Product in which A × B returns a relation instance whose schema contains all the fields of A followed by all the fields of B (both in the same order as appear in their tables). The obtained result from the cross product of A and B contains one tuple〈a, b〉, i.e., the concatenation of the tuple a and b such that a ∈A and b∈ B.

Syntax:

```    SELECT * FROM A CROSS JOIN B;
```
RollNo Name Marks RollNo Name Marks
1 Aashi 98 1 Aashi 98
1 Aashi 98 2 Abhishek 87
1 Aashi 98 3 Anjali 79
1 Aashi 98 4 Brijesh 88
3 Anjali 79 1 Aashi 98
3 Anjali 79 2 Abhishek 87
3 Anjali 79 3 Anjali 79
3 Anjali 79 4 Brijesh 88
4 Brijesh 88 1 Aashi 98
4 Brijesh 88 2 Abhishek 87
4 Brijesh 88 3 Anjali 79
4 Brijesh 88 4 Brijesh 88

What's New

Top Interview Coding Problems/Challenges!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates