Unit2 Relational Algebra
Unit2 Relational Algebra
Unit2 Relational Algebra
1. Select (σ)
2. Project (Π)
3. Union (∪)
4. Set Difference (-)
5. Cartesian product (X)
6. Rename (ρ)
Derived Operations
σ Condition/Predicate(Relation/Table name)
Select Operator (σ) Example
Select a customer who’s city name is “agra”.
Query:
σ Customer_City="Agra" (CUSTOMER)
Output
Project Operator (Π)
table_name1 ∪ table_name2
Union Operator (∪) Example
Query
table_name1 ∩ table_name2
Intersection Operator (∩) Example
Output:
Set Difference (-)
Lets take the same tables COURSE and STUDENT that we have
seen above.
Lets write a query to select those student names that are present in STUDENT
table but not present in COURSE table.
Query:
Π Student_Name (STUDENT) - Π Student_Name
(COURSE)
Output
Note
Just like union, the set difference also comes with the
exception of the same set of attributes in both relations.
Cartesian product (X)
The number of rows in the output will always be the cross product
of number of rows in each table. In our example table 1 has 3 rows
and table 2 has 3 rows so the output has 3×3 = 9 rows.
Rename (ρ)