edited by
468 views

1 Answer

Best answer
3 votes
3 votes
There seems to be some printing error in the question. If there is no typo then answer is D because both of these queries have syntax error. Instance "s" of "employee" table is not declared, hence "s.department" and "s.salary" will throw errors.

If we consider these typos to be unintentional, and go to the spirit of the query then Q1 will give correct result and Q2 is incorrect. So in this case answer will be A.

Q2 will give incorrect result because if any employee has salary greater than salary of (any employee whose dept is 5), it'll be shown in the output. Even those employees whose dept is 5 will be shown, which should not be the case.

Consider the table as below: employee( empid, name, dept, salary)

(1, 'a', 5, 10);
(2, 'b', 5, 20);
(3, 'c', 5, 30);

(4, 'd', 1, 10);
(5, 'e', 2, 10);

 (6, 'f', 3, 50);
 (7, 'g', 4, 60);
 (8, 'h', 6, 70);

Q1 shows empid: 6,7,8

Q2 shows empid: 2,3,6,7,8 (because empid 2 and 3 have salaries greater than empid 1 so they're also on the list.)

If in Q2, instead of "Any" we had used "All", then both queries would give same results.
selected by

Related questions

1 votes
1 votes
1 answer
1
Naveen K Verma asked Jan 10, 2018
720 views
Consider the following instance R.A1234BNull122The number of tuples returned by the following SQL query is _____________. select * from R as R1 where not exists (select...
1 votes
1 votes
2 answers
2
Purple asked Jan 9, 2017
510 views
Consider the following instances $R.$A1234BNull122The number of tuples returned by the following $\text{SQL query}$ is$?$$>$select $*$ from $R$ as $R_{1}$ where not exist...