Reputation: 139
I doing some relational algebra and kinda hit with this question, I did it, but doubt I have done it correctly. So these are the 3 relations:
Musicians: ssn, name, annualIncome
Instruments: instrID, iname, key
Plays: ssn, instrID
The questions is find instrID played by a musician name John.
What I did was:
T1 = proj [condition ssn] ( select [name = John] Musician)
T2 = Plays natural joins Instruments
Result = proj [instruID] (T1 natural joins T2)
It seems like I get every John that play the instruments instead of one specific john... how can I pick one john using relational algebra?
Upvotes: 0
Views: 167
Reputation: 3577
The underlying assumption is that there is only one musician called John: otherwise the question does not seem to make sense.
proj[instrID] (proj[ssn]( select[name = John] Musician) naturalJoin Plays)
should answer the question. You do not need table Instruments
since you can get the instrID
already from Plays
.
Upvotes: 1