We have 3-Relation:
Students(sid, sname)
Courses(cid, cname, dept)
take(sid, cid, grade)
Who Can Describe these relational algebra for me?
We have 3-Relation:
Students(sid, sname)
Courses(cid, cname, dept)
take(sid, cid, grade)
Who Can Describe these relational algebra for me?
The first expression is incorrect or undefined, according to the definition of most popular database books, since the second operand of the division should have attributes that are a subset of the attributes of the first operand (this first paragraph has been edited according to the comments below).
The second expression is a regular division that returns the sid
of the students that have taken all the courses of 'CS'.
The third expression first calculates the cartesian product of all the sid
of students with the cid
of all the 'CS' courses, and from those set removes all the pairs (sid,cid)
present in take
. So, at the end, the set will contains the couples sid
, cid
where sid
identifies a student a cid
a 'CS' course not taken by that student. Finally this set is projected over sid
, so that this expression returns all the students that did not taken all the 'CS' courses. In other words, the complement of the second expression.
Edited
The fourth expression is equivalent to the second one, and this is very easy to prove: consider that this expression is simply equal to:
πsid(students) - (the third expression)
and since the third expression returns the sid
of all the students that did not taken all the 'CS' courses, subtracting this set from the sid
of all the students we found again all (and only) the students that have taken all the 'CS' course. In other words, the complement of the complement, i.e. the original set obtained by the division, that is the second expression.