Carlosdl
29770 pts. | Mar 9 2009 5:52PM GMT
I think we could provide better help if you provide some example data, and show us how the output of the query you are looking for would be.
Kccrosser
1835 pts. | Oct 20 2009 4:16PM GMT
Ok - this is frustrating. Each time I try to finish the above answer I get a page cannot be displayed…
So - the finish is:
– Now, use the results of that to get the output list:
select PResult.*
from PhoneCalls PResult,
(select distinct NumberCalled
from PhoneCalls P1
where exists (select 1 from PhoneCalls P2
where P2.NumberCalled = P1.NumberCalled and P2.CallerName <> P1.CallerName))
I think this will work better than MRDenny’s approach. First, it will not return cases of multiple calls to the same number from the same person (unless there are also calls to that number from other person(s)). Second, a “where exists” clause can terminate as soon as the first record meeting the criteria is found, while the “count” expression requires that all such records must be fetched.
Note the “distinct” in the subquery - the objective is to reduce the subquery return set before joining with the outer table. This will minimize the main join/sort processing at that level.






