InterviewSolution
| 1. |
Consider the following Employee tableID salary DeptName1 10000 EC2 40000 EC3 30000 CS4 40000 ME5 50000 ME6 60000 ME 7 70000 CS How many rows are there in the result of following query?SELECT E.IDFROM Employee EWHERE EXISTS (SELECT E2.salary FROM Employee E2 WHERE E2.DeptName = 'CS' AND E.salary > E2.salary)(A) 0(B) 4(C) 5(D) 6 |
|
Answer» Answer: (C) Explanation: Background:
Here in the above question, there is a correlated subquery because the subquery references the enclosing query (relation Employee renamed as E) Now the correlated query works as follows: SELECT E.ID It takes one tuple from the Employee Relation and displays its ID if the WHERE EXISTS returns true i.e. the subquery returns one or more records. This happens in the case when the tuple from the Employee Relation E has the value of the salary attribute greater than any one of the values of the salary attribute filtered out above. ID salary DeptName Finally it displays their ID’s and the output would be: Hence option (C) 5 rows. |
|