sql - Different select result for exists ? -


i scratching head figure out why these 2 delete results different in sqlite3.

the problem "if 2 students , b friends, , likes b not vice-versa, remove likes tuple. " here, q2. (along actual data)

the schema friend , likes are

.schema friend create table friend(id1 int, id2 int); 

and

.schema likes create table friend(id1 int, id2 int); 

the 2 solutions have come are:

-- correct delete likes not exists       (select 1 likes l2 l2.id1=likes.id2 , l2.id2=likes.id1)  , exists       (select 1 friend likes.id1=friend.id1 , likes.id2=friend.id2); 

and

-- combinng 2 select 1 incorrect delete likes not exists       (select 1 likes l2, friend f        l2.id1=likes.id2 , l2.id2=likes.id1 ,        likes.id1=f.id1 , likes.id2=f.id2); 

you see, difference combined 2 selects one.

the incorrect version wrong because tuple (1782, 1709) incorrectly deleted, should not because tuple not in friend.

in correct query, first subquery uses not exists, while second 1 uses exists. combining them not make sense because meaning of existence of matching friend row negated.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -