sql - NOT IN vs IN Do Not Return Complimentary Results -


hi working through example #7 sql zoo tutorial: select within select. in following question

"find each country belongs continent populations less 25000000. show name, continent , population."

i right answer using not in , sub query this:

select name, continent, population world  continent not in (     select continent world     population > 25000000) 

if on other hand use "in" instead of "not in" , "population < 25000000" not right answer , can not understand why is, there simple reason don't see it, can explain me?

if i'm reading correctly, question asks list every country in continent every country has population below 25000000, correct?

if yes, @ sub query:

select continent world population > 25000000 

you pulling every continent has @ least 1 country w/ population on 25000000, excluding why works.

example: continent alpha has 5 countries, 4 of them small, 1 of them, country charlie has population of 50000000.

so sub query return continent alpha because country charlie fit constraint of population > 25000000. sub query find don't want, that's why using not in work.

on other hand:

select continent world population > 25000000 

if country below 25000000, display continent, not want, because want every country below.

example: continent alpha before, 4 small countries. 4 below 25000000, returned sub query, regardless of fact country charlie has 50000000.

obviously, not best way go it, why first query worked, , second did not.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -