1
$\begingroup$

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

name   hobby
bob    hockey
alice  basketball
mary   cricket
mark   basketball
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)$

$\endgroup$
2
  • $\begingroup$ Could you use aggregating functions? $\endgroup$
    – OmG
    Commented Feb 5, 2018 at 23:58
  • $\begingroup$ Just these ----Union ----Intersection ----Difference ----Selection ----Projection ----Cartesian Join ----Theta join ----Natural join $\endgroup$
    – Tinler
    Commented Feb 6, 2018 at 0:02

1 Answer 1

1
$\begingroup$

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)$$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.