Hi Bonnie,
The query Borislav suggested will be slower because it pulls fields from both tables. It also uses derived table unnecesarly. The adjusted queries below look quite similar and should produce either the same or similar execution plan. I prefer to use query with EXISTS because it clearly indicates the intent of the query.
SELECT * from TopTable
WHERE EXISTS (SELECT * from table2
join table1 ON table1.facID = table2.facIDand table1.billingID = table2.billingID
WHERE toptable.number = table2.bill_number AND toptable.date = table2.service_date )
SELECT TopTable.* from TopTable
JOIN table2 ON toptable.number = table2.bill_number AND toptable.date = table2.service_date
join table1 ON table1.facID = table2.facID and table1.billingID = table2.billingID
>Question for both you, Sergey, and Borislav:
>
>You both recommended different solutions to this query. I like the WHERE EXISTS because it seems simpler than the INNER JOIN that Borislav recommended. But which will give better performance? Anyone looked at an execution plan?
>
--sb--