I am trying to write a relational algebra expression(without the use of division) to pick out those values of 'player' that are present in every 'team' attribute. For example, if my table looks like this:
R2:
Team Player
1 x
1 y
2 x
3 x
3 y
3 z
4 x
4 z
I want to return :
Player
x
since x is the only player that is present in every single team in Team.
Permitted operations: I can use the operations: select, project, rename, joins (natural, cross, inner, outer), set minus, set intersection, aggregations such as sum, count, avg and group by
my attempt:
R1 = (already given, distinct list of Teams) [1,2,3,4]
R2 = the table as stated above
R3 = Count[Team](R1) # number of distinct teams
R4 = GroupBy[Player]_Count[team](R2) # no. of teams grouped by Player
R5 = R4 join[R4.count == R3.count] R3 # only those players with teams = total number of teams
R6 = PROJ[player](R5) # list of players that played in each team
Does this make sense? or is there a more efficient way of doing it?
To improve my understanding, I've also gone through and explicitly written out the relations:
R1:
Team
1
2
3
4
R3:
Count
4
R4:
Player Count
x 4
y 2
z 2
R5:
Player Count
x 4
R6:
Player
x