I have a question involving relational algebra. Suppose I have two relations A and B, where B has a foreign key that references A.

Using relational algebra, how do I select all tuples from A where variable X exists in B? Example:

Relation 1


Relation 2


How do I select from Cars, all the tuples where id exists in Ford? Example:

Cars  car_id  model
       1    a
       2    b
       3    c

Ford  car_id   year
      1        2000
      3        2002

What I would like is: select all from cars where id exists in Ford, which returns:

Result:  car_id  model
         1    a
         3    c

closed as off-topic by ypercubeᵀᴹ, Philᵀᴹ, Kin Shah, Shanky, Colin 't Hart Oct 5 '15 at 13:41

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Too localized - this could be because your code has a typo, basic error, or is not relevant to most of our audience. Consider revising your question so that it appeals to a broader audience. As it stands, the question is unlikely to help other users (regarding typo questions, see this meta question for background)." – ypercubeᵀᴹ, Philᵀᴹ, Kin Shah, Shanky, Colin 't Hart
If this question can be reworded to fit the rules in the help center, please edit the question.


The (somewhat trivial) answer seems to be:

Cars ⋉ Ford

Relational algebra, semijoin (Wikipedia)

Alternatively (in response to a comment):

πR(R ⋈ S)

Not the answer you're looking for? Browse other questions tagged or ask your own question.