Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Multiple fields in Subquery
Message
 
 
À
25/05/2007 09:48:34
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01228038
Message ID:
01228499
Vues:
16
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--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform