Relational algebra, Union Operations, Binary Operations, Difference, Cartesian productÂ
Relational algebra is a query language that processes one or more relations to define another relation.
The basic operation of relational algebra are as follows;
1.Unary operations
Selection, Projection
Operations which involve only one relation are called unary operations.
2.Binary operations:
Operations which involve pairs of relations are called binary operations.
Examples:
Union, Difference, Cartesian product
Selection operation:
It acts like a filter operation on relations.
â c (R)
Returns only those tuples in R that satisfy condition C
Conditions:
Comparison operators = < > =
Logical operators
Name Office Dept Rank
Saleem 400 Cs Assistant
Junaid 220 Econ Lecturer
Ghafoor 160 Econ Assistant
Babar 420 Cs Assistant
Saleem 500 Fin associate
Table: EMP
Example
Select only those employees who are in cs department BUT NOT lecturer AND NAME IS NOT SALEEM
Solution:
â Dept = âcsâ AND-SYMBOL ÂĴ(Rank=âlecturerâ AND-SYMBOL Name=âSaleemâ)(Emp)
Example
Select only those employees who are not in the cs department or lecturer.
â ÂĴ(Rank=âlecturerâ OR-SYMBOL Dept = âcsâ)(EMP)
Example:
Select only those employers who are assistant or in the economics department
â rank=âassitantâ OR-SYMBOL Dept = âEconomicsâ(EMP)
Example: Select only those employees with the last name Saleem who are assistant.
â Name=âSaleemâ AND SYMBOL Rank = âassistantâ (EMP)
Example:
select only those employees who are in the CS department
â Dept = âCsâ (EMP)
“>