I have a relation e.g. R(Owner,Car). How can I return the owners who hold three cars in relational algebra? (and without using aggregate functions)
e.g. something like σ(COUNT(Car)=3)(R) but without using aggregate functions?
e.g.
given return
+-+----+ +-+----+
|a|attX| |a|attX|
+-+----+ +-+----+
|a|attY| ==> |a|attY|
+-+----+ +-+----+
|a|attZ| |a|attZ|
+-+----+ +-+----+
|b|attX|
+-+----+
|c|attW|
+-+----+
|c|attX|
+-+----+
|c|attY|
+-+----+
|c|attZ|
+-+----+
Edit: Thanks for your answers, but I am looking for how to write this in relational algebra. This means in the form using operators like σ, π, X, ⋈, and so on.
Here’s one way of doing it, in SQL using operators that are easy to translate to relational algebra, and using slightly different test data (different types, same names):
p.s. I’m using ‘old style’ (i.e. pre-1992) standard SQL joins, which are widely condemned on Stackoverflow. I’m using them not only because it fits with the OP’s list of available operators but, frankly, in these circumstances I find them much easier to write than using infix
INNER JOINnotation.