简体   繁体   中英

is SQL left outer join equivalent to “not in” select query?

I'm trying to evaluate logic and performance of the following 2 queries. I'm thinking they are identical, but access graph shows different path and significantly different performance. Can someone please explain if those are logically equivalent?

select f.folderId FOLDERS_TO_DEL from store.Folders f 
    where f.ownerUserId not in (select u.userId from store.users u);


select f.folderId FOLDERS_TO_DEL from store.Folders f LEFT JOIN 
    store.Users u ON f.ownerUserId=u.userId WHERE u.userId IS NULL;

Edit: I would like to add that all ID fields are not-nullable in my examples.

No, if there are NULLs in either Folders.ownerUserId or Users.userId , they behave in quite different ways.

A simple SQLfiddle demo with a null in ownerUserId .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM