0

I have 2 tables and I need to write a query in relational algebra that will select all names of teams, who are not working with any client. I have these relations

team( id, name )


client( id, name, teamId ) 
    teamId ⊆ team.id

Tables looks like this

tables

Could you please help me what would be the query in relational algebra? I was thinking about joining these 2 tables and selecting rows there team has Client.teamId as NULL, but I don't know how to formally write it.

filo
  • 67
  • 1
  • 5
  • Right now you are just asking for us to rewrite your textbook with a bespoke tutorial & do your (home)work & you have shown no research or other effort. Please see [ask], hits googling 'stackexchange homework' & the voting arrow mouseover texts. Show parts you can do & refer to your textbook & ask 1 specific researched non-duplicate question re the first place you are stuck. Quote the definitions, theorems & algorithms you are relying on. All the steps are also SO faqs. PS RA calls form a programming language. Give a [mre]. Google 'run relational algebra online'. – philipxy Sep 20 '20 at 13:50
  • Please [use text, not images/links, for text--including tables & ERDs](https://meta.stackoverflow.com/q/285551/3404097). Use images only for what cannot be expressed as text or to augment text. Include a legend/key & explanation with an image. There are many RAs (relational algebras). They differ in operators & even what a relation is. Give operator definitions & your reference for yours. Eg textbook name, edition & page. When giving a business relation(ship)/association or table (base or query result), say what a row in it states about the business situation in terms of its column values. – philipxy Sep 20 '20 at 17:21
  • [Re relational querying.](https://stackoverflow.com/a/24425914/3404097) – philipxy Sep 20 '20 at 17:23

1 Answers1

0

Here are the steps that must be done:

  1. Join Team and Client on Team.id = Client.TeamId and project this relation on Team.id and Team.name. You obtain the id and name of all the teams that work for some client.

  2. Subtract from the relation Team the relation obtained in the previous step: in this way you get all the teams that do not work for some client.

  3. Project the relation obtained at the previous step on Team.name. In this way you obtain the name of the teams that do not work for some client.

The notations for relational algebra are different, here an expression with a typical notation:

πname (team - πid,name(team ⨝id=teamId client))

Renzo
  • 26,848
  • 5
  • 49
  • 61