• edited by
630 views
0 0 votes

The inner query in Q1 will select the employee having max salary from all other employees in all departments(this will return the max salaried employee in the entire company which belongs to dept 5), and outer query will select all employees not in the inner query. Is this interpretation right?

In Q2, inner query gives a list of all salaries of employees in dept 5, and outer query selects those employees from entire company who have salary greater than anyone in dept 5.

Why is the answer Q1 and not Q2? 

1 Answer

0 0 votes
Query 1:

Inner query checks for anyone in the department 5 who have a salary greater than the employee selected in the outer query. If no body exists then that particular employee is picked since NOT EXISTS evaluates to be true. (Hence correct.)

Query 2:

Query is checking for using the ANY clause which says that even if a single person has less salary in department 5 than the current person being evaluated then that person is selected which is not the required answer [We will have to use ALL clause instead to get the correct answer .]
Position:
Show:

Related questions

1 1 vote
1 1 answer
1.8k
1.8k views
Naveen K Verma asked Jan 10, 2018
1,754 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 1 vote
2 2 answers
992
992 views
Purple asked Jan 9, 2017
992 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...
0 0 votes
1 answers 1 answer
878
878 views
1 1 vote
1 1 answer
3.3k
3.3k views
aditi19 asked May 28, 2019
3,339 views
how many tables are required?