I have a table EMPLOYEE and have the following attributes in it: Name, Ssn, Super_Ssn where Super_Ssn is the supervisor's ssn, I have the following query to write:
Retrieve the names of all employees whose supervisor’s supervisor has ‘888665555’ for Ssn.
The given solution:
SELECT
Name
FROM
EMPLOYEE
WHERE
Super_ssn IN ( SELECT SSN FROM EMPLOYEE WHERE SUPER_SSN=‘888665555’ )
While I wrote the following:
SELECT
Name
FROM
EMPLOYEE E,
EMPLOYEE S,
EMPLOYEE SS
WHERE
E.Super_ssn = S.Ssn
AND
S.Super_ssn = SS.Ssn
AND
ss.Ssn=‘888665555’
My question is the following:
- Is there any reason I should resort to their given method if I have a similar query?
- IS there any advantage to using nested queries when not needed?