Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

Combine union with distinct

$
0
0

Situation: I need distinct results from two tables, that both have duplicates. I would like to know if I should combine UNION and DISTINCT.

Example 1 - Only use distinct

SELECT DistinctValueFROM Table1UNIONSELECT DistinctValueFROM Table2

Example 2 - Combine distinct and union

SELECTDISTINCT DistinctValueFROM Table1UNIONSELECTDISTINCT DistinctValueFROM Table2

The results are the same, but are there any performance differences?


Viewing all articles
Browse latest Browse all 7129

Trending Articles