I have a bit of trouble understanding this slide regarding division in Relational Algebra. I did some research and was referred to by many people to On Making Relational Algebra Comprehensible by Lester I McCann. I'm having trouble on understanding one of the slides (Slide 13). I recreate the slides below essentially.
Query: Find the sno value of the suppliers that supply all parts of weight equal to 17.
Relation P
+-------------------------------+ | pno pname color weight city | +-------------------------------+ | P1 Nut Red 12.0 London | | . . . . . . . . . . . . . . . | | P6 Cog Red 19.0 London | +-------------------------------+
Relation SPJ
+-------------------------+ | sno pno jno qty | +-------------------------+ | S1 P1 J1 200 | | . . . . . . . . . . . . | | S5 P6 J4 500 | +-------------------------+
I understand that I need the following schema. Relation A projects a list of sno, pno
. Relation B tells you which pno
equals to 17 weight.
α (sno, pno) β (pno) α ← π sno,pno (SPJ) β ← π pno (σ weight=17 (P))
Result:
Relation α
+---------+ | sno pno | +---------+ | S1 P1 | | S2 P3 | | S2 P5 | | S3 P3 | | S3 P4 | | S4 P6 | | S5 P1 | | S5 P2 | | S5 P3 | | S5 P4 | | S5 P5 | | S5 P6 | +---------+
Relation β:
+-----+ | pno | +-----+ | p2 | | p3 | +-----+
However the slide then goes on to say:
Find the values that do not belong in the answer, and remove them from the list of possible answers.
In our P–SPJ example, the list of possible answers is just the available
sno
values inα
:+-----+ | sno | +-----+ | S1 | | S2 | | S3 | | S4 | | S5 | +-----+
This is where I'm stuck. He says "P - SPJ" in the example but if I do that I don't get the relation above. I don't think it's possible to even do P - SPJ? According to A First Course in Database Systems, when we apply difference operation to relations, the two tables need to have schemas with identical sets of attributes (which P and SPJ do not have)?
If someone could just point me in the right direction that would be great thanks! I have the book A First Course in Database Systems, Chapter 4 which teaches Relational Algebra but unfortunately does not teach division (which I stumbled upon and wanted to learn).