Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

difference btwn DISTINCT and UNION

Status
Not open for further replies.

sunshine9

Programmer
Aug 1, 2002
21
US
Hello,
does anyone know which is better (performance wise) distinct or union? sorry for the sql 101 question.
 
There is no way to compare as each has a different function. The Distinct keyord will eliminate duplicates in a result set when used in a Select query. The Union operator combines multiple row sets (multiple select queries) into one result set.

By default, Union does eliminate duplicates in the final result. Perhaps this is a source of confusion. For simple selects where distinct (non-duplicated) results are desired use the Distinct keyword. When combining result sets into one use the Union operator. Duplicates wil be elimnated unless the ALL keyword is used with the UNION operator. Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top