# relational algebra to get unique pairs

Let's say we are given this table of the relation Person(name, hobby)

name   hobby
bob    hockey
mary   cricket
rick   snowboarding
andy   hockey


How would I use relational algebra to find the hobby that had only one person had.

It should give me

hobby
cricket
snowboarding


My ATTEMPT:

$R1 := \rho_{P2}(Person)$

$R2 := R1 \bowtie_{P2.hobby = P1.hobby \text{ } AND \text{ } P2.name <> P1.name} R2$

$R3 := \pi_{hobby} (R2)$

• Could you use aggregating functions? – OmG Feb 5 '18 at 23:58
• Just these ----Union ----Intersection ----Difference ----Selection ----Projection ----Cartesian Join ----Theta join ----Natural join – Tinler Feb 6 '18 at 0:02

You need more carefully defined $\theta$-join and then set difference:
$$R1 := \rho_{name1/name,hobby1/hobby}(Person)$$ $$R2 := Person \bowtie_{(hobby=hobby1) \land (name \neq name1)} R1$$ $$R3 := \pi_{hobby}(Person) \setminus \pi_{hobby}(R2)$$