Mike
Mike

Reputation: 11

Set difference in relational calculus

Given this schema:

Musicians(ssn, name, annualIncome)
Instruments(instrID, iname, key)
Plays(ssn, instrID)

In relational calculus, I am to find the instrId played only by musicians whose name is ‘Andrew’, i.e., are not played by any musician with any other name.

I've come up with the following:

{T1.instrID | ∃T1 ∈ Plays ¬(∃P2 ∈ Plays (P2.name =/ 'Andrew' AND P1.name /= 'Andrew' ))}

where '=/' is 'not equal'

Is it correct?

Upvotes: 0

Views: 859

Answers (1)

Erwin Smout
Erwin Smout

Reputation: 18408

(1) find the instruments played by anyone not named andrew
(2) subtract that from the set of all instruments (***).

("subtract that" in calculus is SUCH THAT NOT EXISTS ...)

You should have noticed that your solution cannot possibly be correct, because there is no reference what so ever to "named andrew", which is like a crucial part of the problem specification.

(***) it is rather unclear from the problem specification whether instruments that are not played at all (by anyone) should appear in the result. Depending on the answer, it might have to be "from the set of instruments that are played by at least one player".

Upvotes: 2

Related Questions