0% found this document useful (0 votes)
24 views2 pages

SQL Projection and Relational Algebra

Projection in SQL and Relational Algebra is an operation that selects specific columns from a table while removing unwanted ones. In Relational Algebra, it automatically removes duplicates, whereas SQL requires the DISTINCT keyword to achieve the same effect. The document provides examples of projection using a STUDENT table and highlights key features of projection in both relational algebra and SQL.

Uploaded by

ahmedjahanzeb227
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

SQL Projection and Relational Algebra

Projection in SQL and Relational Algebra is an operation that selects specific columns from a table while removing unwanted ones. In Relational Algebra, it automatically removes duplicates, whereas SQL requires the DISTINCT keyword to achieve the same effect. The document provides examples of projection using a STUDENT table and highlights key features of projection in both relational algebra and SQL.

Uploaded by

ahmedjahanzeb227
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Projection in SQL (Relational Algebra Concepts)

Notes: Projection in SQL and Relational Algebra

What is Projection?

In Relational Algebra, Projection is an operation that selects specific columns (attributes) from a relation

(table). It removes unwanted columns and keeps only those needed.

Symbol: pi

Example (Relational Algebra):

If we have a table STUDENT(id, name, age, course) and we want only name and course, then:

pi_name, course (STUDENT)

This means: Project the name and course columns from the STUDENT relation.

Equivalent in SQL:

SELECT name, course FROM STUDENT;

Key Features of Projection:

- Works on: Columns/Attributes only

- Removes: Duplicate rows (in Relational Algebra)

- SQL behavior: SQL allows duplicates unless DISTINCT is used

- Order of rows: Not preserved in relational algebra

- Output: New relation with selected columns

With Duplicate Removal:

In Relational Algebra, projection automatically removes duplicates.

To do this in SQL, use DISTINCT:

SELECT DISTINCT name FROM STUDENT;

Result Example:

STUDENT Table:
Projection in SQL (Relational Algebra Concepts)

| id | name | age | course |

|----|-------|-----|--------|

| 1 | Ali | 20 | CSE |

| 2 | Sara | 21 | EEE |

| 3 | Rani | 22 | ME |

| 4 | Sara | 21 | EEE |

Relational Algebra Query:

pi_name (STUDENT)

Result:

| name |

|-------|

| Ali |

| Sara |

| Rani |

(In Relational Algebra, duplicates are removed.)

In SQL:

SELECT name FROM STUDENT;

-> Shows all values, including duplicates.

SELECT DISTINCT name FROM STUDENT;

-> Removes duplicates, matches relational algebra behavior.

You might also like