0 votes 0 votes Answer given on virtual gate is a1,a3,a2 I'm getting a1,a3,a2,a1 as duplicate values are allowed in SQL. What is my mistake here ? Databases sql databases + – just_bhavana asked Sep 18, 2017 just_bhavana 782 views answer comment Share Follow See all 6 Comments See all 6 6 Comments reply Show 3 previous comments mohit199 commented Sep 18, 2017 reply Follow Share @just_bhavana I am also getting a1, a2, a2, a1. Please check. 0 votes 0 votes just_bhavana commented Sep 18, 2017 reply Follow Share @joshi_nitish @mohit can you elaborate your solution? 0 votes 0 votes mohit199 commented Sep 18, 2017 reply Follow Share @just_bhavana As @joshi_nitish mentioned, the query is correlated. So, for every tuple of 'R' you have to go through every tuple of S. It is similar to a nested loop. for(1 to n){ for(1 to m){ } } In the above pseudo code, you will run the inner loop 'm' times for every value of outer loop. The given query works in a similar manner. 1st row of R- c2 is not present in any tuple of S. So, nothing gets selected from inner query.Thus, the outer query will produce a1. Repeat this procedure for all the tuples of R, you will get the same answer as mine. 1 votes 1 votes Please log in or register to add a comment.
Best answer 0 votes 0 votes Answer will be a1 a2 a2 a1 The above query is correlated query which means for every tuple of outside query the inner query will be executed completely. Meaning of the symbol <> is not equal to Now, For the tuple a1 b1 c2 we will check inner query.. C2 of table R does not match with any value in S. C therefore it will return zero attribute.. Which is not equal to b1 therefore a1 will be selected. For tuple a2 b4 c1 : c1 matches in table S corresponding value is b1 in table S which does not match with b4 therefore condition is true and a2 is selected.. Similarly a3 not selected and a2 a1 selected again.. Final answer will be a1 a2 a2 a1 vamp_vaibhav answered Nov 25, 2017 • selected Nov 27, 2017 by just_bhavana vamp_vaibhav comment Share Follow See all 0 reply Please log in or register to add a comment.
1 votes 1 votes a1,a2,a2,a1 will be the answer,as you have to select those A whose B is not equal to any B of S in which R.c=S.c Red_devil answered Sep 18, 2017 Red_devil comment Share Follow See 1 comment See all 1 1 comment reply Hira Thakur commented Oct 24, 2017 reply Follow Share plz explain outer query how it executed??/ 1 votes 1 votes Please log in or register to add a comment.