I'm trying to convert an sql query into tuple relational calculus, but there is a NOT EXIST that causes me to be stuck.
SQL query:
SELECT num FROM a a1, b b1
WHERE a1.num = b1.no AND a1.name = "Tim"
AND NOT EXIST
(SELECT * FROM a a2, b b2
WHERE a2.num = b2.no AND a2.name = "Tim"
AND b2.rating > b1.rating)
I already started with:
{ t: num | ∃a1 ∈ a ∃b1 ∈ b [ t(num) = a1(num) ∧ a1.name = "Tim" ∧ ¬∃a2 ∈ a ...
this is where I'm stuck. How do I show that it is NOT EXISTS from both a2 and b2? If I write ¬∃a2 ∈ a ¬∃b2 ∈ b then this is going to be a doubly nested sql query and not the one listed above.
You want there to not exist
a2andb2per theWHERE.SQL expression
corresponds to tuple calculus expression
In SQL there
EXISTSa row in the subquery if and only if there exista2andb2row values per itsWHEREto form that row. SoNOT EXISTSsuch an SQLa2plusb2pair when it's not the case that there are calculusa2andb2where....