Advertisements
Advertisements
प्रश्न
Explain the different operators in Relational algebra with suitable examples.
Advertisements
उत्तर
Relational Algebra Operations from Set Theory
- UNION (∪)
- INTERSECTION (∩)
- DIFFERENCE (-)
- CARTESIAN PRODUCT (X)
SELECT (symbol: σ)
General form σ<sub>c</sub> ( R) with a relation R and a condition C on the attributes of R.
The SELECT operation is used for selecting a subset with tuples according to a given condition. Select filters out all tuples that do not satisfy C.
| Studno | Name | Course | Year |
| cs1 | Kannan | Big Data | II |
| cs2 | Gowri Shankar | R language | I |
| cs3 | Lenin | Big Data | I |
| cs4 | Padmaja | Python Programming | I |
PROJECT (symbol: II)
The projection eliminates all attributes of the input relation but those mentioned in the projection list.
Example 1 using Table A
π<sub>course</sub> (STUDENT)
Result
| Course |
| Big Data |
| R language |
| Python Programming |
Course Big Data R language PythonProgramming
Note: duplicate row is removed in the result UNION (Symbol: u)
It includes all tuples that are in tables A or in B. It also eliminates duplicates. Set A Union Set B would be expressed asAuB
Example 2:
Consider the following tables
| Table A | |
| Studno | Name |
| cs1 | Kannan |
| cs3 | Lenin |
| cs4 | Padmaja |
| Table B | |
| Studno | Name |
| cs1 | Kannan |
| cs2 | GowriShankarn |
| cs3 | Lenin |
Result
| Table A ∪ B | |
| Studno | . |
| cs1 | Kannan |
| cs2 | GowriShankarn |
| cs3 | Lenin |
| cs4 | Padmaja |
SET DIFFERENCE ( Symbol: -)
The result of A – B, is a relation that includes all tuples that are in A but not in B. The attribute name of A has to match with the attribute name in B.
Example 4:
( using Table B)
Result
| Table A - B | |
| cs4 | Padmaja |
INTERSECTION (symbol: ∩) A∩B
Defines a relation consisting of a set of all tuples that is in both in A and B. However, A and B must be union-compatible
Example 5:
(using Table B)
| A ∩ B | |
| cs1 | Kannan |
| cs3 | Lenin |
PRODUCT OR CARTESIAN PRODUCT (Symbol: X)
Cross product is a way of combining two relations. The resulting relation contains, both relations being combined.
A × B means A times B, where the relation A and B have different attributes.
This type of operation is helpful to merge columns from two relations.

Cartesian Product
| Table A | Table B | ||
| studno | name | studno | subject |
| cs1 | Kannan | cs28 | Big Data |
| cs2 | Gowri Shankar | cs62 | R language |
| cs4 | Padmaja | cs25 | python programming |
Cartesian product : Table A × Table B
| studno | name | course | subject |
| cs1 | Kannan | cs28 | Big Data |
| cs1 | Kannan | cs62 | R language |
| cs1 | Kannan | cs25 | python programming |
| cs2 | Gowri Shankar | cs28 | Big Data |
| cs2 | Gowri Shankar | cs62 | R language |
| cs2 | Gowri Shankar | cs25 | python programming |
| cs4 | Padmaja | cs28 | Big Data |
| cs4 | Padmaja | cs62 | R language |
| cs4 | Padmaja | cs25 | python programming |
