mark
mark

Reputation: 2931

Relational Algebra - Divide

If I have the following tables and I perform R1/R2 in relational algebra, would the result be a table with A values 1 and 3? I am a bit confused as I know 3 would be a result as it contains both 5 and 1, but the result 1 has additional values for B aside from the matching ones so would this also be included and why?

     R1          R2
    +---+---+   +---+
    | A | B |   | B |
    |---|---|   |---|
    | 1 | 1 |   | 5 |
    | 1 | 2 |   | 1 |
    | 1 | 3 |   +---+
    | 1 | 4 |
    | 2 | 3 |
    | 2 | 4 |
    | 3 | 5 |
    | 3 | 1 |
    | 1 | 5 |
    | 5 | 7 |
    | 5 | 8 |
    +---+---+

Upvotes: 2

Views: 2494

Answers (1)

mehdi.loa
mehdi.loa

Reputation: 575

In relational databases Divide is defined as:
R1(Y,X) DIVIDE R2(X) = R1[Y] MINUS ((R1[Y] TIMES R2) MINUS R1)[Y]

remember that R1[Y] is another form of "PROJECT R1 over Y".
so the result is {1,3}

Upvotes: 3

Related Questions