0

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

Cars(car_id,model)    

Relation 2

Ford(car_id,year)

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
0

1 Answer 1

4

The (somewhat trivial) answer seems to be:

Cars ⋉ Ford

Relational algebra, semijoin (Wikipedia)

Alternatively (in response to a comment):

πR(R ⋈ S)
0

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