Hi my friend. You just have to add the clause DISTINCT:
SELECT DISTINCT CustomerName FROM CustomersBut if you use several data sources (tables, views) then you must use the UNION operator, which automatically combines the result of two or more SELECT statements in one result set and eliminates duplicates records by default.
SELECT CustomerName FROM Customers UNION SELECT CustomerName2 FROM Customers2If you need all records (including duplicates), add the option ALL to the UNION operator.
Select Statement UNION [ALL] Select Statement
For More Information
- What do you think about this answer? E-mail us at [email protected] with your feedback.
- The Best Microsoft SQL Server Web Links: tips, tutorials, scripts, and more.
- The Best SQL Web Links
- Have a SQL Server tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
- Ask your technical SQL Server questions -- or help out your peers by answering them -- in our live discussion forums.
- Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.