401 views
2 votes
2 votes

2 Answers

1 votes
1 votes

Answer would be D

Q1: In the inner query in the WHERE clause the stament is  : s.salary >= e.salary. So e.sal will be compared against its own value and will always return true, therefore no rows will be selected

Q2:If e.sal is greater than any sal in the table it will o/p it. so it will print all the salaries except the least

Thus the o/p of both the queries is also not the same

0 votes
0 votes

Here Q1 seems to be correct.. let me explain why...

As question says who get higher salary than anyone in department 5 i.e. we want those employees whose salary is higher than ANY employee we take from department 5 i.e. from ALL employees(great english statement...). So now let's take each query one by one:

Q1: As per this query it says select those employees from outer query in such a way that whenever inner query finds that it's(inner query's) salary is greater that outer query's salary(as it is like nested loop so for each outer row we have to lookup whole inner table) then it will return one row which is against NOT EXISTS i.e. this query won't return anything if at least one row return by inner query hence it will give us ONLY those employees whose salary is higher than ALL employees of dept 5

Q2: It's obvious from Q1 explanation that we can't use ANY...if we change it to ALL then it will work like Q1.

So answer is option (A).

Related questions

0 votes
0 votes
1 answer
2
rayhanrjt asked Jan 6, 2023
717 views
Write SQL command to find DepartmentID, EmployeeName from Employee table whose average salary is above 20000.
2 votes
2 votes
1 answer
3
Subhrangsu asked Jun 18, 2022
431 views
Write SQL query to show all employees hired on June 4,1984 (non-default format)emp(empno,ename,job,mgr,hiredate,sal,comm,deptno)
1 votes
1 votes
3 answers
4
aditi19 asked May 18, 2019
1,200 views
Class(name, meets_at, room, fid)Faculty(fid, fname, deptid)Find the names of faculty members who teach in every room in which some class is taught