sqlite - The logic of WHERE Clause along with > operator and the sub-query -


i don't logic query 3 below, , hope give me idea. query 3, select id, name, age, salary company age > (select age company salary < 20000);

the sub-query find out result salary < 20000 first, , query2 shown below. , parent query find out result using age's record table company(total of 7 record: 18,19,22,23,24,29,37) compare age's result sub-query(total of 4 record: 18,19,23,29) , show greater record based on age.

i expect result should show id 7 below, since record met condition. greater age result of sub-query(query 2) 29, record age on 29.


id          name        age         salary   7           vicky       37          32500.0  

unfortunately expectation not met, , show me result query 3 below.

i hope understand logic how work query 3, , hope assist.

1.sqlite> select id, name, age, salary company;


id          name        age         salary  1           john        24          21000.0    2           davy        22          20000.0    3           kenny       19          9700.0     4           henry       23          13555.0    5           sam         18          17000.0    6           ray         29          8000.0     7           vicky       37          32500.0    

2.sqlite> select id, name, age, salary company salary < 20000;


id          name        age         salary   3           kenny       19          9700.0     4           henry       23          13555.0    5           sam         18          17000.0    6           ray         29          8000.0     

3.sqlite> select id, name, age, salary company age > (select age company salary < 20000);


id          name        age         salary     1           john        24          21000.0    2           davy        22          20000.0    4           henry       23          13555.0    6           ray         29          8000.0     7           vicky       37          32500.0    

at guess, since doesn't throw error (which seems better idea; see col. 32's comment):

sqlite picks first returned age. age should random, going results shown in query 2 , assuming consistency, first result 19. then, picks ages larger 19, see in results of query 3.

shuffle things around or create set of data, , see if query 2 , 3 consistent assumption.

someone else may know internals of sqlite enough explain why happens.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -