In this case... the exists query will be faster.
In terms of performance, distinct is a relatively expensive operation. Also, in terms of performance, Exists is a relatively fast operation.
Comparing execution plans, the join version has an extra step:
[tt]
StmtText
-----------------------
Select Table1.Table1Name
From Table1
Where Exists(Select 1 From Table2 Where Table1.Table1Id = Table2.Table1Id)
StmtText
-----------------------------------------
|--Merge Join(Left Semi Join, MERGE

[Table1].[Table1Id])=([Table2].[Table1Id]), RESIDUAL

[Table1].[Table1Id]=[Table2].[Table1Id]))
|--Clustered Index Scan(OBJECT

[DatabaseName].[dbo].[Table1].[PK_Table1_Table1Id]), ORDERED FORWARD)
|--Index Scan(OBJECT

[DatabaseName].[dbo].[Table2].[Table2_Table1Id]), ORDERED FORWARD)
StmtText
--------------------------------
Select Table1.Table1Name
From Table1
Inner Join (Select Distinct Table1Id From Table2) As A
On Table1.Table1Id = A.Table1id
StmtText
-----------
|--Hash Match(Inner Join, HASH

[Table2].[Table1Id])=([Table1].[Table1Id]), RESIDUAL

[Table2].[Table1Id]=[Table1].[Table1Id]))
|--Stream Aggregate(GROUP BY

[Table2].[Table1Id]))
| |--Index Scan(OBJECT

[DatabaseName].[dbo].[Table2].[Table2_Table1Id]), ORDERED FORWARD)
|--Index Scan(OBJECT

[DatabaseName].[dbo].[Table1].[Table1_Table1Name]))
[/tt]
Eventhough there is no group by statement, it appears as though SQL is implementing the distinct operation as though it were a group by. Also notice that the exists query is implemented through a left semi join where the join version is implemented through a has match.
The following 2 queries generate identical execution plans.
Code:
Select m.*
from master
inner join(Select [!]distinct[/!] Details.Master_FK fk from Details
)D
on m.Master_Pk=D.fk
Select m.*
from master
inner join(Select Details.Master_FK fk from Details [!]Group By Details.Master_FK[/!]
)D
on m.Master_Pk=D.fk
-
George
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom