Databases Reference
In-Depth Information
SELECT DISTINCT ( ContactID )
FROM Sales . SalesOrderHeader
SELECT ContactID
FROM Sales . SalesOrderHeader
GROUP BY ContactID
Listing 2-26.
Both queries produce the same results and will use the same execution plan, as shown in
Figure 2-22:
Figure 2-22: A Hash Aggregate used by a query with a DISTINCT keyword.
Joins
I started talking about joins and join orders in Chapter 1 , Introduction to Query
Optimization . In this section I will talk about the three join operators that SQL
Server uses to implement logical joins: the Nested Loops Join, the Merge Join and
the Hash Join. It is important to understand that no join algorithm is better than
the others, and that the Query Optimizer will select the best join algorithm depending
on the specific scenario, as I'll explain here.
Search WWH ::




Custom Search