Reputation: 9
Given the following table schema
customer (name: string, credit: integer)
allowance (no: string, type: string)
asker(cname: string, lno: string)
asker.cname and asker.lno are foreign keys referencing customer, respectively allowance , whose keys are name, respectively no (number)
I am trying to write the relational algebra for the query to find pairs of names of customers who share the same allowance. Avoid listing a customer with himself (Tim, Tim) and avoid listing the same over and over (ex. (Tim, Jane) and (Jane, Tim) should be one)
I have tried is:
ρ(Cust1, π no (allownace)
ρ(Cust2, π no (allownace)
π name, name((Cust1 ∩ Cust2)(customer))
I believe this is incorrect. Specially, I am having trouble where I need to find customers with the same allowance and also avoiding the customer himself and repeating.
Upvotes: 0
Views: 3353
Reputation: 15118
Eliminate (Tim, Tim) via σ (name1 <> name2). (The relation(ship) is non-reflexive.)
Eliminate just one of (Tim, Jane) & (Jane, Tim) but not (Tim, Tim) via σ (name1 op name2) where op is one of <= or >=. (The relation(ship) is anti-symmetric.)
Eliminate both cases by σ (name1 op name2) where op is one of < or >. (The relationship is non-reflexive and anti-symmetric.)
(Re querying & algebra see this answer.)
Upvotes: 1