Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Multiple fields in Subquery
Message
 
 
To
25/05/2007 09:48:34
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01228038
Message ID:
01228499
Views:
22
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--
Previous
Reply
Map
View

Click here to load this message in the networking platform