Is there a relational algebra equivalent of the SQL expression NOT IN
?
For example if I have the relation:
A1 | A2
----------
x | y
a | b
y | x
I want to remove all tuples in the relation for which A1 is in A2. In SQL I might query:
SELECT
*
FROM
R
WHERE
R.A1 NOT IN
(
SELECT
A2
FROM
R
)
/
What is really stumping me is how to subquery inside the relational algebra selection operator, is this possible?:
σsome subquery hereR
In relational algebra, you can do this using a carthesian product. Something like:
R - ρa1,a2(πa11,a21(σA11 = A22(ρa11,a21(R) x ρa12, a22(R))))
That gives you the rows that were matched. Subtract this from R to find the rows that where not matched.