Relational Algebra in DBMS: Operations With Solved Examples

DBMS Chapter 08 · Relational Algebra Visual Lab
Relational Algebra in DBMS: Operations With Solved Examples

Relational Algebra is a step-by-step language for working with relations. You start with one or more relations, apply an operation such as selection, projection, union or join, and get a new relation as the result. In this chapter, every operation is explained in very easy language using the same college database, visual before-and-after tables, memory shortcuts and solved examples so you can understand what each symbol actually does instead of memorising formulas.

Very easy English Pictorial before → after Solved examples All major operations Exam + viva ready Checked: 18 September 2026
First understand the idea

What Is Relational Algebra in DBMS?

Relational Algebra is a procedural query language for the relational model. It tells us what operation to apply to one or more relations to produce another relation as the result.

Think of it like a machine. You put a table into the machine, choose an operation, and the machine gives you another table.

Input RelationStart table
OperationSelect, project, join...
ConditionWhat you want
ResultNew relation
Next StepApply another operation if needed

Shortcut #1: Input → Operation → Output

Relation + Operation = New Relation

This property is called closure: the result of a relational-algebra operation is again a relation, so you can apply another operation to it.

If relation, tuple, attribute or domain are not fully clear yet, revise Relational Model in DBMS: Relation, Tuple, Attribute & Domain Explained first. Relational Algebra is easier once those four words feel natural.

We will use one database throughout

Our College Database for Every Solved Example

We will keep the same small database in the whole chapter so you do not waste time learning a new example in every section.

STUDENT Relation

student_idnamebranchsemester
S01AshaCSE2
S02RaviECE2
S03NehaCSE1
S04AmanME3

COURSE Relation

course_idtitlecredits
C101DBMS4
C102OS4
C103Networks3

ENROLLMENT Relation

student_idcourse_idgrade
S01C101A
S01C102B
S02C101B
S03C101A
Pictorial learning

Interactive Operation Explorer

Click an operation. Watch what changes between input and output.

IDNameBranch
S01AshaCSE
S02RaviECE
S03NehaCSE
σ
branch = CSE
IDNameBranch
S01AshaCSE
S03NehaCSE
Selection keeps rows that satisfy a condition. Columns stay the same.
Operation map

Types of Relational Algebra Operations

Different textbooks group operations slightly differently. A useful beginner grouping is:

Basic / Fundamental Operations

Selection, Projection, Union, Set Difference, Cartesian Product and Rename are commonly treated as core operations.

Derived / Common Additional Operations

Intersection, Join and Division can be described using the basic operations, but they are very important in practical learning and exams.

Shortcut #2: S-P-U-D-C-R

Selection · Projection · Union · Difference · Cartesian Product · Rename

Then add the high-value derived operations: Intersection, Join and Division.

Operation 01

Selection (σ): Choose Rows

Simple meaning

Selection chooses tuples (rows) that satisfy a condition. It does not choose columns.

Symbolσ (sigma)
ChangesRows
KeepsSame attributes/columns
Think“Filter the rows.”

Solved Example 1: Find all CSE students

σ branch = 'CSE' (STUDENT)
Read the conditionWe only want rows where branch = CSE.
Check each tupleAsha = CSE ✓, Ravi = ECE ✗, Neha = CSE ✓, Aman = ME ✗.
Keep matching tuplesAsha and Neha remain.
student_idnamebranchsemester
S01AshaCSE2
S03NehaCSE1

Solved Example 2: Find CSE students in semester 2

σ branch = 'CSE' AND semester = 2 (STUDENT)

Only Asha satisfies both conditions.

Shortcut #3: Selection = Select rows

σ → Filter rows
Operation 02

Projection (π): Choose Columns

Simple meaning

Projection chooses attributes (columns) from a relation.

Symbolπ (pi)
ChangesColumns
Main ideaShow only the attributes you need.

Solved Example: Show only student name and branch

π name, branch (STUDENT)
namebranch
AshaCSE
RaviECE
NehaCSE
AmanME

Important point: duplicate tuples

In pure relational algebra, relations are sets. If projection produces duplicate tuples, duplicate copies are removed.

Example: projecting only branch from STUDENT gives CSE, ECE and ME. CSE appears for two students in the original relation, but the projected relation contains one CSE tuple.

Shortcut #4: Projection = Pick columns

π → Columns

Selection = rows. Projection = columns. This is the most important pair to remember.

Most common exam combination

Selection + Projection Together

Many real questions need both row filtering and column choosing.

Question: Show names of CSE students

π name (σ branch = 'CSE' (STUDENT))
Inner operation firstSelection finds only CSE tuples.
Outer operation nextProjection keeps only the name attribute.
Final resultAsha, Neha.

Shortcut #5: Read relational algebra from inside to outside

Just like brackets in mathematics, solve the inner expression first.

Operation 03

Union (∪): Combine Tuples From Two Compatible Relations

Simple meaning

Union gives all tuples that are present in relation A or relation B or both.

Symbol∪
NeedsUnion-compatible relations
DuplicatesRemoved in pure relational algebra

What does union-compatible mean?

Same number of attributesBoth relations should have matching degree.
Compatible corresponding domainsMatching columns should represent compatible kinds of values.

Solved Example

Suppose CSE_STUDENT and ECE_STUDENT both contain only (student_id, name).

CSE_STUDENT ∪ ECE_STUDENT

The result contains all students from both relations, without duplicate tuples.

Shortcut #6: Union = Put both lists together

A ∪ B = in A OR B
Operation 04

Intersection (∩): Keep Common Tuples

Simple meaning

Intersection returns tuples that are present in both compatible relations.

Symbol∩
Think“Common in both.”

Solved Example

Let relation A contain students who joined a coding club. Let relation B contain students who joined a robotics club. If both relations have the same structure:

A ∩ B

The result gives students who are members of both clubs.

Shortcut #7: Intersection = AND

A ∩ B = in A AND B
Operation 05

Set Difference (−): Keep What Is in A but Not in B

Simple meaning

Set Difference returns tuples that are in the first relation but not in the second.

Symbol−
Order mattersA − B is usually different from B − A.

Solved Example

A = students registered for DBMS.
B = students who submitted DBMS assignment.

A − B

Result: students registered for DBMS but who have not submitted the assignment.

Shortcut #8: Difference = First list minus second list

A − B = in A but NOT in B
Operation 06

Cartesian Product (×): Pair Every Tuple With Every Tuple

Simple meaning

Cartesian Product combines every tuple of relation A with every tuple of relation B.

Symbol×
If A has m tuplesand B has n tuples
Resultm × n tuples

Mini Example

Relation A

(S01, Asha)
(S02, Ravi)

Relation B

(C101, DBMS)
(C102, OS)

A has 2 tuples and B has 2 tuples. Therefore A × B contains 4 combined tuples.

student_idnamecourse_idtitle
S01AshaC101DBMS
S01AshaC102OS
S02RaviC101DBMS
S02RaviC102OS

Cartesian Product by itself often creates many meaningless combinations. It becomes very useful as a building block for joins, where a condition removes unwanted combinations.

Shortcut #9: Product = Everybody meets everybody

m rows × n rows = m×n combinations
Operation 07

Rename (ρ): Give a Relation or Attribute a New Name

Simple meaning

Rename changes the name of a relation or its attributes for use inside an expression.

Symbolρ (rho)
Useful whenSelf-joins, long names, same attribute names or temporary results.

Example

ρ S (STUDENT)

This gives STUDENT the temporary relation name S.

You may also see notation that renames attributes depending on the textbook convention.

Shortcut #10: Rename = Nickname

Think of ρ as giving a relation a short nickname so a complex expression becomes easier to write.

Operation 08

Join: Combine Related Tuples

Simple meaning

A join combines tuples from two relations when they satisfy a relationship condition.

In practical database work, join is one of the most important ideas because related data is usually stored in separate relations.

STUDENT

S01, Asha
S02, Ravi
S03, Neha

student_id matches Combine related tuples only

ENROLLMENT

S01, C101, A
S02, C101, B
S03, C101, A

Theta Join (θ Join)

A theta join uses a general comparison condition such as =, <, >, ≤, ≥ or ≠.

STUDENT ⋈ STUDENT.student_id = ENROLLMENT.student_id ENROLLMENT

The exact symbol style may differ in notes. The important idea is that a condition decides which combined tuples survive.

Equi Join

An equi join is a theta join whose condition uses equality.

STUDENT.student_id = ENROLLMENT.student_id

Because the matching attributes may appear from both relations, an equi-join result can contain both copies unless projection removes one.

Natural Join (⋈)

A natural join automatically matches attributes with the same name and compatible meaning, and normally keeps one copy of the common join attribute in the result.

Shortcut #11: Join = Product + Matching Condition

Conceptually, you can imagine:

Join ≈ Cartesian Product → Filter matching tuples

Solved Example: Show student names with grades

π name, grade (
  STUDENT ⋈ STUDENT.student_id = ENROLLMENT.student_id ENROLLMENT
)
namegrade
AshaA
AshaB
RaviB
NehaA

The first step joins STUDENT with ENROLLMENT using student_id. The projection then keeps only name and grade.

Operation 09 · the one students fear

Division (÷): Find “All Of These” Cases

Simple meaning

Division is useful for queries that contain the idea “all.”

Symbol÷
Typical question“Find students who completed all required courses.”

Suppose ENROLLED(student_id, course_id) contains which student took which course. REQUIRED(course_id) contains the courses every student must complete.

ENROLLED ÷ REQUIRED

The result contains student IDs that are paired with every course present in REQUIRED.

Very small solved example

ENROLLED

S01–C1
S01–C2
S02–C1

REQUIRED

C1
C2

S01 has both C1 and C2. S02 has only C1. Therefore:

ENROLLED ÷ REQUIRED = {S01}

Shortcut #12: Division = “Who has ALL?”

÷ → ALL condition
Slow method for division

How to Solve Division Without Getting Confused

Look at the divisorList all required values.
Take one candidate from the first relationExample: S01.
Check every required valueDoes S01 appear with C1? Yes. With C2? Yes.
Keep only complete candidatesIf even one required value is missing, remove that candidate.

This manual method is perfect for small semester-exam questions.

Multi-operation solved problem

Complete Solved Example With Selection, Join and Projection

Question

Find the names of CSE students who are enrolled in DBMS (course C101).

Step 1: Select CSE students

CSE = σ branch = 'CSE' (STUDENT)

Step 2: Select DBMS enrollments

DBMS_ENROLL = σ course_id = 'C101' (ENROLLMENT)

Step 3: Join them on student_id

MATCHED =
CSE ⋈ CSE.student_id = DBMS_ENROLL.student_id DBMS_ENROLL

Step 4: Project only name

π name (MATCHED)

Final Answer

name
Asha
Neha

Shortcut #13: Filter → Connect → Display

Selection → Join → Projection

This three-step pattern solves many relational-algebra questions.

Rules you should not skip

Union Compatibility and Other Important Rules

Union, Intersection, DifferenceRequire union-compatible relations.
SelectionCondition should use attributes of the input relation.
ProjectionProjected attributes must exist in the input relation.
Cartesian ProductMay require renaming when attribute names collide.
JoinThe join condition should represent the intended relationship.
DivisionAttribute structure must fit the “all required values” pattern.
Useful algebra properties

Important Relational Algebra Properties

You do not need advanced proofs for a basic DBMS exam, but a few properties help simplify expressions.

Selection is commutativeApplying condition A then B gives the same final tuples as B then A.
Selections can be combinedTwo selection conditions can often be written as one AND condition.
Projection may remove extra attributes earlyBut never remove an attribute needed later for a join or condition.
Join order can sometimes be rearrangedFor compatible inner joins, DBMS optimizers may choose efficient execution orders.
ClosureEach operation returns a relation, so operations can be nested.
Set semanticsPure relational algebra treats relations as sets, so duplicate tuples are not separate members.

These ideas become useful later when you study query processing and optimization.

Connect theory to SQL

Relational Algebra vs SQL

Relational AlgebraMeaningCommon SQL Connection
Selection σChoose rowsWHERE
Projection πChoose columnsSELECT column_list
Union ∪Combine compatible resultsUNION
Difference −A but not BEXCEPT / MINUS depending on DBMS
Cartesian Product ×Every pairCROSS JOIN
Join ⋈Combine related tuplesJOIN ... ON
Rename ρTemporary namingAliases using AS

SQL and Relational Algebra are not identical languages, but relational algebra gives the theoretical foundation for understanding how relation-oriented queries can be expressed and transformed.

The earlier Integrity Constraints in DBMS chapter explains which relation states are valid. Relational Algebra now explains how we operate on those valid relations.

Common exam mistakes

Do Not Confuse These Operations

Selection ≠ ProjectionSelection filters rows. Projection chooses columns.
Union ≠ JoinUnion stacks compatible tuples. Join combines attributes from related tuples.
Intersection ≠ JoinIntersection keeps identical tuples present in both compatible relations.
Difference order mattersA − B and B − A usually give different results.
Product ≠ JoinProduct creates every combination; join keeps combinations that satisfy a condition.
Natural Join ≠ Equi Join exactlyNatural join automatically uses common attribute names and normally removes duplicate common columns.
Projection may remove duplicatesPure relational algebra uses set semantics.
Division ≠ normal arithmetic divisionIt solves “for all” style relational questions.
Union needs compatibilityYou cannot union unrelated relation structures directly.
Solve inside firstNested algebra expressions are normally read from inner operations outward.
Write according to marks

How to Write Relational Algebra in Semester Exams

2 marks

Definition + one operation

Define Relational Algebra in one line and explain the asked operation with symbol and tiny example.

5 marks

Operation + solved relation

Write meaning, symbol, input table, expression and result table. Selection/projection questions are ideal for this format.

8-10 marks

Compare multiple operations

Explain basic operations, set-operation compatibility, joins and one multi-step solved expression. Add division if it is in your syllabus.

For clean answer presentation, use How to Write High-Scoring Answers in University Semester Exams. For unit priority, use the previous-year-paper method.

Practice questions with answers

Practice Questions With Answers

1. What is Relational Algebra?

Relational Algebra is a procedural query language in which operations are applied to one or more relations to produce a new relation.

2. What is the difference between selection and projection?

Selection chooses rows that satisfy a condition. Projection chooses required columns or attributes.

3. Why must relations be union-compatible for union?

Union combines tuples position by position, so the relations need the same number of attributes and compatible corresponding domains.

4. What does Cartesian Product do?

It pairs every tuple of the first relation with every tuple of the second relation. If the relations have m and n tuples, the result has m×n tuples.

5. What is a natural join?

A natural join combines tuples by automatically matching common attribute names with compatible meaning and normally keeps one copy of the common attribute.

6. What is an equi join?

An equi join is a join whose comparison condition uses equality.

7. When is division useful?

Division is useful for “all” queries, such as finding students who completed all required courses.

8. Does projection remove duplicate tuples?

Yes, in pure relational algebra relations use set semantics, so duplicate projected tuples are represented only once.

9. How is join related to Cartesian Product?

A join can be understood conceptually as forming combinations and then keeping only those that satisfy the join condition.

10. What does closure mean in Relational Algebra?

Closure means the result of a relational-algebra operation is again a relation, so another relational-algebra operation can be applied to it.

60-second revision

Relational Algebra One-Minute Revision Sheet

Selection σChoose rows.
Projection πChoose columns.
Union ∪All tuples from A or B.
Intersection ∩Common tuples in A and B.
Difference −Tuples in A but not B.
Product ×Every tuple paired with every tuple.
Rename ρGive temporary relation/attribute names.
Theta JoinJoin using a comparison condition.
Equi JoinTheta join using equality.
Natural JoinAutomatic join on common compatible attributes.
Division ÷“Who has all?” queries.
ClosureEvery operation returns a relation.

Ultimate memory line

Rows = σ · Columns = π · Combine = ∪/⋈ · All = ÷
Frequently asked questions

Frequently Asked Questions

What is Relational Algebra in DBMS in simple words?

Relational Algebra is a way to process relations using operations such as selection, projection and join to produce new relations.

Which are the basic operations of Relational Algebra?

Common fundamental operations include selection, projection, union, set difference, Cartesian product and rename. Intersection, join and division are also important derived or additional operations.

What is the difference between selection and projection?

Selection filters rows using a condition, while projection chooses the required columns.

What is the difference between Cartesian Product and Join?

Cartesian Product creates every possible tuple combination. A join keeps combinations that satisfy a relationship condition.

What is division in Relational Algebra?

Division is used for “all” queries, such as finding students who completed all required courses.

What should I study after Relational Algebra?

Study SQL in detail, relational calculus, functional dependencies and normalization. These topics build directly on relational querying and design.

Next chapter

What Should You Learn After Relational Algebra?

Next: SQL Commands and Query Writing

Relational Algebra gives you the theory of selecting, projecting, combining and joining relations. The next step is to learn how these ideas appear in practical SQL using SELECT, WHERE, JOIN, UNION, GROUP BY, HAVING and subqueries.

After SQL, continue with relational calculus, functional dependencies and normalization. If you want video revision after reading the chapter, use the DBMS YouTube study guide as a secondary resource.

Tags

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Join Telegram Exam updates and free resources