0 0 votes Databases sql query + – Rudra Pratap 2.3k views answer comment Share Follow Print See all 14 Comments 14 14 Comments reply MiNiPanda commented Sep 1, 2018 reply Follow flag Is it C? not sure 0 0 replyShare Shubhgupta commented Sep 1, 2018 reply Follow flag Yes C is right answer. (3rd highest) 0 0 replyShare Deepanshu commented Sep 1, 2018 reply Follow flag 2 = means? 0 0 replyShare MiNiPanda commented Sep 1, 2018 reply Follow flag Deepanshu I was having doubt whether we could write like that or not.. but I took it in this way like if the subquery returns result = 2 (i.e. count(distinct(Emp2.salary)) =2) then 2=2 will be true and the outer query will print salary ...but if the subquery doesn't return 2 then the where condition will be false and no salary will be printed for that case.. 0 0 replyShare Deepanshu commented Sep 1, 2018 reply Follow flag @MiNiPanda HOW R U SAYING C .??? NOT GETTING THAT 0 0 replyShare Shubhgupta commented Sep 1, 2018 reply Follow flag @MiNiPanda, your explanation is correct then what was the doubt. @Deepanshu, suppose values in employee salary table ID Salary a 1 b 2 c 3 d 4 run inner query for every tuple- for (a,1) count will be 3. for (b,2) count will be 2. for (c,3) count will be 1. for (d,4) count will be 0. now only (b,2) tuple is match and 2 will be printed which is 3rd highest. 2 2 replyShare MiNiPanda commented Sep 1, 2018 reply Follow flag I was having doubt in the syntax where 2=(subquery) ..haven't seen like this before. 0 0 replyShare Shubhgupta commented Sep 1, 2018 reply Follow flag similar kind of question https://gateoverflow.in/1400/gate2005-77-isro2016-55 and exactly same question came in BARC also . 1 1 replyShare Deepanshu commented Sep 1, 2018 reply Follow flag @Shubhgupta i got your point .but your example above example is little wrong you are saying 2 willl be printed which is 3rd highest which is not i think..... thanku for the point @MiNiPanda included :) :) 1 1 replyShare Shubhgupta commented Sep 1, 2018 reply Follow flag buddy in salary row 3rd highest is 2 only. Isn't it? 0 0 replyShare MiNiPanda commented Sep 1, 2018 reply Follow flag Deepanshu If you check the query properly you will notice that it means that a's salary is lesser than 3 persons.. For tuple (a,1) compare will all the 4 tuples.. 1>1=F ,2>1= T ,3>1 =T ,4>1= T count=3 as 3 cases are true 0 0 replyShare Shubhgupta commented Sep 1, 2018 reply Follow flag your assumption is wrong try that gate 2005 question and come to this. you will understand better. and (a,1) count is 3, it means that there are 3 rows which are having greater salary then a. 0 0 replyShare Deepanshu commented Sep 2, 2018 i edited by Deepanshu Sep 2, 2018 reply Follow flag @Shubhgupta @MiNiPanda MY MISTAKE :/ I AM NOT THINKING ABOUT COORELATED RELATION 0 0 replyShare Shaik Masthan commented Sep 2, 2018 reply Follow flag @minipanda we can write it in that form also... Even in C also we can write in that way... coming to co-related query, form a sample table which can give different result for different options, then run the query on that table... This is a simple method ( as per my opinion ) 1 1 replyShare Please log in or register to add a comment.
1 1 vote C. This is a correlated nested query. Where inner query gives a count of employee having more salary than the employee in outer query and 2 checks that only 2 people have more salary than him. sidlewis answered Sep 1, 2018 sidlewis comment Share Follow 0 reply Please log in or register to add a comment.