When a query that includes the DISTINCT keyword is issued, all duplicate rows are excluded from the results and only unique rows are returned. To accomplish this, SQL Server first creates a worktable to store the results of the query, including duplicates, just as if the DISTINCT keyword were not included. It then sorts the rows in the worktable and discards the duplicate rows. Finally, the rows from the worktable are returned, ensuring that no duplicate rows will appear in the output.
SELECT DISTINCT city FROM authors
STEP 1 The type of query is INSERT The update mode is direct Worktable created for DISTINCT FROM TABLE authors Nested iteration Table Scan TO TABLE Worktable 1 STEP 2 The type of query is SELECT This step involves sorting FROM TABLE Worktable 1 Using GETSORTED Table Scan