Quantcast
Channel: ฟอรัม Getting started with SQL Server
Viewing all articles
Browse latest Browse all 8428

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 8428

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>