Hello, I have 2 tables namely Person_Organization and Person_Organization_other and nested query is :-
SELECT Person_Organization_id FROM Person_Organization_other
WHERE company_name IN
(
SELECT company_name from Person_Organization_other
WHERE Person_Organization_id IN
(
SELECT Person_Organization_Id FROM Person_Organization
WHERE person_id =117 AND delete_flag=0
)
)
whereas the above query's corresponding query with join that I tried is :-
SELECT poo.Person_Organization_id
FROM Person_Organization_other poo, Person_Organization_other poo1, Person_Organization po
WERE poo1.Person_Organization_id=po.Person_Organization_Id
AND po.person_id=117
AND po.delete_flag=0
AND poo.company_name=poo1.company_name
GROUP BY poo.Person_Organization_id
However the nested query is found to take less time as compared to it's corresponding query with joins. I used SQL profiler trace to compare times of executed queries. For the nested quey it took 30 odd ms. For the joined quiery it took 41 odd ms
I was under the impression that as a rule nested queries are less perfomant and should be "flattened out" using joins.
Could someone explain what i am doing wrong?
regards Nitin