# Basic Operators in Relational Algebra

C++Server Side ProgrammingProgramming

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_idName
1Computer science
2Information Technology
3mechanical

1RamDelhi18
4FaizDelhi22

### Table 3: Hostel

1RamDelhi18
3nehaJhansi21

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

4FaizDelhi22
• 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
1Ram
2Akash
3neha

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

1RamDelhi181Computer science
1RamDelhi182Information Technology
1RamDelhi183mechanical
3nehaJhansi211Computer science
3nehaJhansi212Information Technology
3nehaJhansi213mechanical
• 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

1RamDelhi18
4FaizDelhi22
3nehaJhansi21
• 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

ρ(new_name , old_name)