SQL query to a relational algebra

1 Answer 80 Views
Miscellaneous
Kratik
Top achievements
Rank 1
Kratik asked on 25 Sep 2022, 08:18 AM

I need to translate the SQL query to a relational algebra expression. 

SELECT P.Name 
FROM Players P, Games G
WHERE P.Id =  G.PlayerId
    AND P.Game = 'Football' AND G.Season ='2019'
where: Players (Id, Name, Game) Games (PlayerId, GameCode, Season)

1 Answer, 1 is accepted

Sort by
0
jhonson
Top achievements
Rank 1
Iron
Iron
answered on 06 Feb 2023, 07:42 AM

I think this might help you with relational algebra expression for the given SQL query is:

  • π Name (Players ÷⋈ Id=PlayerId ((Players ⨝ Games)
  • ⨝ (Game = 'Football' AND Season = '2019')))

Explanation:

  • π Name: Projection to get only the "Name" attribute.
  • Players ÷⋈ Id=PlayerId: Natural Join between Players and Games on "Id" and "PlayerId".
  • Players ⨝ Games: Cartesian product of Players and Games.
  • (Game = 'Football' AND Season = '2019'): Selection to get only the tuples with "Game" equal to "Football" and "Season" equal to "2019".
Tags
Miscellaneous
Asked by
Kratik
Top achievements
Rank 1
Answers by
jhonson
Top achievements
Rank 1
Iron
Iron
Share this question
or