1. Relational Algebra
1
Fall 2001 Database Systems 1
Relational Algebra
• A relation is a set of tuples. Each relational
algebra operation takes as input a list of
relations and produces a single relation.
• General form:
OperatorArguments (List of Relations)
New Relation
• After each operation, the remaining attributes
are carried to the new relation. The attributes
may be renamed, but their domain remains the
same.
Fall 2001 Database Systems 2
Set Theoretic Operations
• Regular set operations on relations
• A set operation requires two participating relations R and
S to be compatible
– R and S should have the same attributes
• R(Name:D1, Email:D2)
• S(Name:D1, Email:D2, Address:D3)
• T(Name:D1, Email:D4)
• V(Name:D1, Email:D2)
Which relations above are union (set operation)
compatible?
– Union compatibility may require type conversion
(casting).
15. Relational Algebra
15
Fall 2001 Database Systems 29
Problem 1
Find the name and email of owners of items located in
“Boston”
A := Items WHERE Location = “Boston”
B := A
¢¡ Owners
Result := B[Owners.Name, Owners.Email]
Fall 2001 Database Systems 30
Problem 2
Find the identifiers and amount of bids placed by
buyer “Roberts”
A := Buyers WHERE Name = “Roberts”
B := A
¢¡ Bids
Result := B[Bid, Amount]
16. Relational Algebra
16
Fall 2001 Database Systems 31
Problem 3
Find the names of buyers who placed a bid on an item
owned by “Brown”
A := Owners WHERE Name = “Brown”
B := (A
¢¡ Items) [Iid]
C := B
¢¡ Bids
Result := (C
¢¡ Buyers) [Buyers.Name]
Fall 2001 Database Systems 32
Problem 4
Find the identifier of items with more than one bid
A := Bids[Bid, Iid]
B := A x Bids[Bid,Iid]
C := B WHERE (A.Bid Bids.Bid)
AND (A.Iid = Bids.Iid)
Result := C[Iid]
17. Relational Algebra
17
Fall 2001 Database Systems 33
Problem 5
Find the names of items all buyers placed a bid on
A := (Bids[Iid, BuyId]) ÷ (Buyers[Buyid])
B := A
¢¡ Items
Result := B[Name]