Explain following in context of Relational algebra: 1. Selection 2. Theta(θ) – Join 3. Projection.
1. SELECTION (σ)
The SELECT operation is used for selecting a subset of the tuples according to a given selection condition. Sigma(σ) Symbol denotes it. It is used as an expression to choose tuples which meet the selection condition. Select operator selects tuples that satisfy a given predicate.
Notation: σp(r)
Where
σ stands for selection predicate,
r stands for relation,
p is prepositional logic formula,
which may use connectors like AND, OR and NOT,
These terms may use relational operators like: =, ≠, ≥, < , >, ≤.
Example 1: σ topic = "Database" (Tutorials)
Output : Selects tuples from Tutorials where topic = 'Database'.
Example 2: σ topic = "Database" and author = "ABC"( Tutorials)
Output: Selects tuples from Tutorials where the topic is 'Database' and 'author' is ABC.
Example 3: σ sales > 50000 (Customers)
Output: Selects tuples from Customers where sales is greater than 50000
2. Theta (θ) Join
Theta join combines tuples from different relations provided they satisfy the theta condition. The join condition is denoted by the symbol θ.
Notation: R1 ⋈θ R2
R1 and R2 are relations having attributes (A1, A2, .., An) and (B1, B2,.. ,Bn) such that the attributes don’t have anything in common, that is R1 ∩ R2 = Φ.
Theta join can use all kinds of comparison operators.
Consider the following table
Table 1 : Student
SID Name Std
101 Siya 10
102 Riya 11
Table 2 : Subjects
Class Subject
10 Math
10 English
11 Music
11 Sports
Example: STUDENT ⋈Student.Std = Subject.Class SUBJECT
Output:
Student_detail
SID Name Std Class Subject
101 Siya 10 10 Math
101 Siya 10 10 English
102 Riya 11 11 Music
102 Riya 11 11 Sports
3. Projection(π)
The projection eliminates all attributes of the input relation but those mentioned in the projection list. The projection method defines a relation that contains a vertical subset of Relation.
This helps to extract the values of specified attributes to eliminates duplicate values. (pi) symbol is used to choose attributes from a relation. This operator helps you to keep specific columns from a relation and discards the other columns.
Notation: ∏A1, A2, An(r)
Where A1, A2 , An are attribute names of relation r.
Duplicate rows are automatically eliminated, as relation is a set
Consider the following table
Table : Customer
Customer ID Customer Name Status
1 Google Active
2 Amazon Active
3 Apple Inactive
4 Alibaba Active
Example: Π CustomerName, Status (Customers)
Output:
Customer Name Status
Google Active
Amazon Active
Apple Inactive
Alibaba Active
Follow Us