---
description: What is Relational Algebra? Relational algebra is a widely used procedural query language. It collects instances of relations as input and gives occurrences of relations as output. It uses various ope
title: Relational Algebra in DBMS with Examples
image: https://www.guru99.com/images/relational-algebra-dbms-1.png
---

 

[Skip to content](#main) 

**⚡ Smart Summary**

Relational Algebra in DBMS is a procedural query language that takes relations as input and produces new relations as output. It groups operators into unary, set, and binary categories, providing the theoretical foundation that SQL engines translate into executable query plans.

* 🔍 **Start with unary operators:** SELECT, PROJECT, and RENAME filter rows, pick columns, and rename attributes on a single relation.
* 📚 **Apply set theory:** UNION, INTERSECTION, DIFFERENCE, and CARTESIAN PRODUCT combine union-compatible relations into new results.
* 🔗 **Join intentionally:** Theta, Equi, and Natural joins handle inner matches, while Left, Right, and Full Outer joins keep unmatched tuples with nulls.
* 📐 **Watch compatibility:** Always confirm that arity, attribute names, and domains align before any set or union operation.
* 🤖 **Use AI to translate:** AI assistants convert algebra expressions into SQL, explain operator precedence, and flag missing join conditions in plain English.

[ Read More ](javascript:void%280%29;) 

![Relational Algebra in DBMS](https://www.guru99.com/images/relational-algebra-dbms-1.png)

## What is Relational Algebra?

**Relational Algebra** is a procedural query language that accepts instances of relations as input and returns new instances of relations as output. It applies a fixed set of operators recursively on one or more relations, and the result of each operator is itself a relation that can be fed into the next operation. SQL engines lean on this algebra to plan and execute queries.

## Basic Relational Algebra Operations

Relational algebra operators fall into three groups.

### Unary Relational Operations

* SELECT (σ)
* PROJECT (π)
* RENAME (ρ)

### Operations from Set Theory

* UNION (∪)
* INTERSECTION (∩)
* DIFFERENCE (−)
* CARTESIAN PRODUCT (×)

### Binary Relational Operations

* JOIN
* DIVISION

The sections below walk through each operator with worked examples.

## SELECT (σ)

The **SELECT** operation chooses a subset of tuples that satisfy a given predicate. The sigma symbol `σ` denotes it:

```
σp(r)
```

where `σ` is the operator, `p` is the propositional condition, and `r` is the relation (table). SELECT preserves the schema and discards rows that fail the predicate.

**Example 1**

```
σ topic = "Database" (Tutorials)
```

Selects tuples from _Tutorials_ where the topic equals “Database”.

**Example 2**

```
σ topic = "Database" AND author = "guru99" (Tutorials)
```

Selects tuples from _Tutorials_ where the topic is “Database” and the author is guru99.

**Example 3**

```
σ sales > 50000 (Customers)
```

Selects tuples from _Customers_ whose sales value is greater than 50,000.

## Projection (π)

The **projection** operator removes every attribute from the input relation except those listed, producing a vertical subset. Projection also eliminates duplicate rows that result from dropping attributes. The pi symbol `π` denotes it.

**Example:** consider the following table.

| CustomerID | CustomerName | Status   |
| ---------- | ------------ | -------- |
| 1          | Google       | Active   |
| 2          | Amazon       | Active   |
| 3          | Apple        | Inactive |
| 4          | Alibaba      | Active   |

Projecting on CustomerName and Status:

```
π CustomerName, Status (Customers)
```

| CustomerName | Status   |
| ------------ | -------- |
| Google       | Active   |
| Amazon       | Active   |
| Apple        | Inactive |
| Alibaba      | Active   |

### RELATED ARTICLES

* [DBMS Schemas: Internal, Conceptual, External ](https://www.guru99.com/dbms-schemas.html "DBMS Schemas: Internal, Conceptual, External")
* [What is DBMS (Database Management System)? ](https://www.guru99.com/what-is-dbms.html "What is DBMS (Database Management System)?")
* [Difference Between DDL and DML in DBMS ](https://www.guru99.com/difference-between-ddl-and-dml.html "Difference Between DDL and DML in DBMS")
* [Top 50 Oracle Interview Questions and Answers (2026) ](https://www.guru99.com/oracle-interview-questions.html "Top 50 Oracle Interview Questions and Answers (2026)")

## Rename (ρ)

The **rename** operator is a unary operation that gives a new name to an attribute (or to an entire relation). For example, `ρ(a/b) R` renames attribute _b_ of relation _R_ to _a_. Rename is particularly useful when you need to perform a self-join or join two relations that share attribute names.

## Union Operation (∪)

The **UNION** operator, denoted by `∪`, returns every tuple that appears in either relation A or relation B, automatically removing duplicates.

```
Result ← A ∪ B
```

For a union to be valid:

* A and B must have the same number of attributes (same arity).
* The corresponding attribute domains must be compatible.
* Duplicate tuples are removed automatically.

**Example.** Consider these two tables:

| Table A  |          | Table B |          |          |
| -------- | -------- | ------- | -------- | -------- |
| column 1 | column 2 |         | column 1 | column 2 |
| 1        | 1        |         | 1        | 1        |
| 1        | 2        |         | 1        | 3        |

`A ∪ B` gives:

| column 1 | column 2 |
| -------- | -------- |
| 1        | 1        |
| 1        | 2        |
| 1        | 3        |

## Set Difference (−)

The minus symbol denotes **set difference**. The result of `A − B` is a relation containing all tuples that are in A but not in B.

* A and B must be union-compatible.
* Attribute names and domains must align.

**Example: A − B**

| column 1 | column 2 |
| -------- | -------- |
| 1        | 2        |

## Intersection (∩)

The **intersection** operator, denoted by `∩`, defines a relation containing every tuple that appears in both A and B. A and B must be union-compatible.

[](https://www.guru99.com/images/1/100518%5F0535%5FRelationalA4.png)

_Visual definition of intersection._

**Example: A ∩ B**

| column 1 | column 2 |
| -------- | -------- |
| 1        | 1        |

## Cartesian Product (×) in DBMS

The **Cartesian product** combines every tuple of one relation with every tuple of another, merging their columns. On its own the result is rarely useful, but combined with a SELECT predicate it becomes the foundation of JOIN. It is also called the cross product or cross join.

**Example: σ column 2 = ‘1’ (A × B)**

The expression returns every row of `A × B` whose `column 2` value is 1.

| column 1 | column 2 |
| -------- | -------- |
| 1        | 1        |
| 1        | 1        |

## Join Operations

A **join** is a Cartesian product followed by a selection predicate. Joins are denoted by the `⋈` symbol and let you combine related tuples from different relations in a meaningful way.

**Types of join:**

* **Inner joins:** Theta join, Equi join, Natural join.
* **Outer joins:** Left, Right, and Full Outer joins.

## Inner Join

In an **inner join**, only tuples that satisfy the matching criteria are included; the rest are discarded.

### Theta Join

The general form of JOIN is the **Theta join**, denoted by θ. Theta join can use any comparison condition in its selection criteria.

```
A ⋈θ B
```

For example:

```
A ⋈ A.column 2 > B.column 2 (B)
```

| column 1 | column 2 |
| -------- | -------- |
| 1        | 2        |

### Equi Join

When a Theta join uses only equality conditions, it becomes an **Equi join**.

```
A ⋈ A.column 2 = B.column 2 (B)
```

| column 1 | column 2 |
| -------- | -------- |
| 1        | 1        |

Equi join is one of the most heavily used join styles, and the [RDBMS](https://www.guru99.com/relational-data-model-dbms.html) query optimizer typically pours significant effort into making it efficient.

### Natural Join (⋈)

A **Natural join** requires a common attribute (column) between the relations. The shared attribute must have the same name and domain. The result contains one copy of the matching column.

Consider these two tables.

| Table C |        |
| ------- | ------ |
| Num     | Square |
| 2       | 4      |
| 3       | 9      |

| Table D |      |
| ------- | ---- |
| Num     | Cube |
| 2       | 8    |
| 3       | 27   |

`C ⋈ D` produces:

| Num | Square | Cube |
| --- | ------ | ---- |
| 2   | 4      | 8    |
| 3   | 9      | 27   |

## Outer Join

An **outer join** keeps tuples that satisfy the matching criteria _and_ tuples that do not, filling missing columns with NULL.

### Left Outer Join (A ⟕ B)

The left outer join keeps every tuple in the left relation. If a row in A has no matching row in B, the attributes contributed by B are filled with NULL.

[](https://www.guru99.com/images/1/100518%5F0535%5FRelationalA6.png)

Consider the following tables:

| Table A |        |
| ------- | ------ |
| Num     | Square |
| 2       | 4      |
| 3       | 9      |
| 4       | 16     |

| Table B |      |
| ------- | ---- |
| Num     | Cube |
| 2       | 8    |
| 3       | 18   |
| 5       | 75   |

`A ⟕ B` gives:

| Num | Square | Cube |
| --- | ------ | ---- |
| 2   | 4      | 8    |
| 3   | 9      | 18   |
| 4   | 16     | NULL |

### Right Outer Join (A ⟖ B)

The right outer join keeps every tuple in the right relation. If a row in B has no matching row in A, the columns contributed by A are filled with NULL.

[](https://www.guru99.com/images/1/100518%5F0535%5FRelationalA8.png)

`A ⟖ B` gives:

| Num | Cube | Square |
| --- | ---- | ------ |
| 2   | 8    | 4      |
| 3   | 18   | 9      |
| 5   | 75   | NULL   |

### Full Outer Join (A ⟗ B)

The full outer join keeps every tuple from both relations, regardless of whether the join condition matched. Missing values on either side become NULL.

`A ⟗ B` gives:

| Num | Square | Cube |
| --- | ------ | ---- |
| 2   | 4      | 8    |
| 3   | 9      | 18   |
| 4   | 16     | NULL |
| 5   | NULL   | 75   |

## Operator Reference Summary

Use this reference table to recall what each operator does at a glance.

| Operation (Symbol)    | Purpose                                                                  |
| --------------------- | ------------------------------------------------------------------------ |
| SELECT (σ)            | Selects a subset of tuples that satisfy a given predicate.               |
| PROJECT (π)           | Keeps only the listed attributes and removes duplicate rows.             |
| UNION (∪)             | Returns every tuple appearing in either A or B without duplicates.       |
| SET DIFFERENCE (−)    | Returns tuples in A that are not in B.                                   |
| INTERSECTION (∩)      | Returns tuples appearing in both A and B.                                |
| CARTESIAN PRODUCT (×) | Combines every tuple of A with every tuple of B.                         |
| INNER JOIN            | Keeps only tuples that match the join condition.                         |
| THETA JOIN (θ)        | General-form join using any comparison predicate.                        |
| EQUI JOIN             | Theta join that uses only equality comparisons.                          |
| NATURAL JOIN (⋈)      | Joins relations on attributes that share the same name and domain.       |
| LEFT OUTER JOIN (⟕)   | Keeps every tuple from the left relation, fills right with NULL.         |
| RIGHT OUTER JOIN (⟖)  | Keeps every tuple from the right relation, fills left with NULL.         |
| FULL OUTER JOIN (⟗)   | Keeps every tuple from both relations, filling missing values with NULL. |

## FAQs

⚡ What is the difference between relational algebra and SQL?

Relational algebra is a procedural mathematical language used to define operations on relations. SQL is a declarative query language that database engines translate into algebra-style execution plans internally.

🚀 What is meant by union compatibility?

Two relations are union compatible when they have the same number of attributes and each corresponding attribute shares the same domain. UNION, INTERSECTION, and DIFFERENCE all require union compatibility.

💡 Why is a Cartesian product rarely used on its own?

A Cartesian product multiplies every row of A with every row of B, producing huge intermediate relations with little meaning. It is normally followed by a SELECT predicate to become a useful join.

🔒 Does relational algebra preserve duplicates?

No. Pure relational algebra treats relations as sets, so duplicates are automatically eliminated after every operation. SQL behaves differently — it works on multisets and only removes duplicates when DISTINCT is used.

📐 What is the division operator used for?

The DIVISION operator answers “for all” queries — for example, find customers who ordered every product in a catalogue. It returns the tuples of one relation that match every tuple of another.

⏱️ When should I use an outer join instead of an inner join?

Use an outer join when unmatched rows still carry meaning — for example, listing every customer along with optional order data. Inner joins drop those unmatched rows; outer joins keep them with NULL fillers.

🤖 How can AI help me learn relational algebra?

AI assistants translate algebra expressions into SQL and back, explain operator precedence step by step, and flag missing join predicates that would otherwise turn a query into a slow Cartesian product.

✍️ Can AI generate algebra expressions from natural-language questions?

Yes. AI tools turn plain-English questions such as “customers from India who bought every product” into algebra trees with SELECT, PROJECT, and DIVISION operators, then convert them into runnable SQL.

#### Summarize this post with:

ChatGPT Perplexity Grok Google AI 

**Stay Updated on AI** **Get Weekly AI Skills, Trends, Actionable Advice.** 

##### Sign up for the newsletter

Subscribe for Free 

You have successfully subscribed.  
Please check your inbox. 

![AI-Newsletter]() Chosen by over **350,000+** professionals 

[Scroll to top ](#wrapper)Scroll to top 

× 

Toggle Menu Close 

Search for: 

Search

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.guru99.com/#organization","name":"Guru99","sameAs":["https://www.facebook.com/Guru99Official","https://twitter.com/guru99com"],"logo":{"@type":"ImageObject","@id":"https://www.guru99.com/#logo","url":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","contentUrl":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","caption":"Guru99","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.guru99.com/#website","url":"https://www.guru99.com","name":"Guru99","publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https://www.guru99.com/images/relational-algebra-dbms-1.png","url":"https://www.guru99.com/images/relational-algebra-dbms-1.png","width":"600","height":"250","inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/relational-algebra-dbms.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":"1","item":{"@id":"https://www.guru99.com","name":"Home"}},{"@type":"ListItem","position":"2","item":{"@id":"https://www.guru99.com/dbms","name":"DBMS"}},{"@type":"ListItem","position":"3","item":{"@id":"https://www.guru99.com/relational-algebra-dbms.html","name":"Relational Algebra in DBMS with Examples"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/relational-algebra-dbms.html#webpage","url":"https://www.guru99.com/relational-algebra-dbms.html","name":"Relational Algebra in DBMS with Examples","dateModified":"2026-05-29T15:42:41+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"primaryImageOfPage":{"@id":"https://www.guru99.com/images/relational-algebra-dbms-1.png"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/relational-algebra-dbms.html#breadcrumb"}},{"@type":"Person","@id":"https://www.guru99.com/author/fiona","name":"Fiona Brown","description":"I'm Fiona brown, a Full Stack Developer with over a decade of experience, sharing practical guides on robust and scalable application development.","url":"https://www.guru99.com/author/fiona","image":{"@type":"ImageObject","@id":"https://www.guru99.com/images/fiona-brown-author.png","url":"https://www.guru99.com/images/fiona-brown-author.png","caption":"Fiona Brown","inLanguage":"en-US"},"worksFor":{"@id":"https://www.guru99.com/#organization"}},{"articleSection":"DBMS","headline":"Relational Algebra in DBMS with Examples","description":"What is Relational Algebra? Relational algebra is a widely used procedural query language. It collects instances of relations as input and gives occurrences of relations as output. It uses various ope","keywords":"dbms, sql","speakable":{"@type":"SpeakableSpecification","cssSelector":[".entry-title",".summary"]},"@type":"Article","author":{"@id":"https://www.guru99.com/author/fiona","name":"Fiona Brown"},"dateModified":"2026-05-29T15:42:41+05:30","image":{"@id":"https://www.guru99.com/images/relational-algebra-dbms-1.png"},"copyrightYear":"2026","name":"Relational Algebra in DBMS with Examples","subjectOf":[{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What is the difference between relational algebra and SQL?","acceptedAnswer":{"@type":"Answer","text":"Relational algebra is a procedural mathematical language used to define operations on relations. SQL is a declarative query language that database engines translate into algebra-style execution plans internally."}},{"@type":"Question","name":"What is meant by union compatibility?","acceptedAnswer":{"@type":"Answer","text":"Two relations are union compatible when they have the same number of attributes and each corresponding attribute shares the same domain. UNION, INTERSECTION, and DIFFERENCE all require union compatibility."}},{"@type":"Question","name":"Why is a Cartesian product rarely used on its own?","acceptedAnswer":{"@type":"Answer","text":"A Cartesian product multiplies every row of A with every row of B, producing huge intermediate relations with little meaning. It is normally followed by a SELECT predicate to become a useful join."}},{"@type":"Question","name":"Does relational algebra preserve duplicates?","acceptedAnswer":{"@type":"Answer","text":"No. Pure relational algebra treats relations as sets, so duplicates are automatically eliminated after every operation. SQL behaves differently \u2014 it works on multisets and only removes duplicates when DISTINCT is used."}},{"@type":"Question","name":"What is the division operator used for?","acceptedAnswer":{"@type":"Answer","text":"The DIVISION operator answers 'for all' queries \u2014 for example, find customers who ordered every product in a catalogue. It returns the tuples of one relation that match every tuple of another."}},{"@type":"Question","name":"When should I use an outer join instead of an inner join?","acceptedAnswer":{"@type":"Answer","text":"Use an outer join when unmatched rows still carry meaning \u2014 for example, listing every customer along with optional order data. Inner joins drop those unmatched rows; outer joins keep them with NULL fillers."}},{"@type":"Question","name":"How can AI help me learn relational algebra?","acceptedAnswer":{"@type":"Answer","text":"AI assistants translate algebra expressions into SQL and back, explain operator precedence step by step, and flag missing join predicates that would otherwise turn a query into a slow Cartesian product."}},{"@type":"Question","name":"Can AI generate algebra expressions from natural-language questions?","acceptedAnswer":{"@type":"Answer","text":"Yes. AI tools turn plain-English questions such as \"customers from India who bought every product\" into algebra trees with SELECT, PROJECT, and DIVISION operators, then convert them into runnable SQL."}}]}],"@id":"https://www.guru99.com/relational-algebra-dbms.html#schema-1106853","isPartOf":{"@id":"https://www.guru99.com/relational-algebra-dbms.html#webpage"},"publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/relational-algebra-dbms.html#webpage"}}]}
```
