I am working a problem from the Stanford DB class and have a question. I have 2 tables. The first table has 2 fields, so we have T1(ID1,ID2). The second table has some more columns.
If I do
select T1.ID1, T1.ID2
from T1, T2 as X, T2 as Y, T2 as Z
where <condition>
except
select T1.ID2, T1.ID1
from T1, T2 as X, T2 as Y, T2 as Z
where <different condition>;
then I get 2 tuples
A1 | B1
A2 | B2
as a result. This is just what I was expecting.
The issue is how do I delete the rows from T1 using these tuples?
I tried
delete
from T1
where ID1=(<select from above using only the first variable in the select>)
and ID2=(<select from above using only the second variable in the select>);
This didn’t work and I don’t see a way to do it.
Any clues?
Thanks
Not sure if this is possible in SQLite, but you could give it a try:
That might be sub-optimal and maybe you could instead split your EXCEPT query like this: