SQL SELECT DISTINCT – Removing Duplicates from Table = Unique values

By | 5. 11. 2019

SELECT DISTINCT is a command used to show unique records in a table. Its use is broad but it is mainly used to remove duplicities in the records when taking multiple views on data.

Hint: If we select more than 1 column, DISTINCT will return unique combinations of selected columns


Syntax is easy, all you need to do is add magic word “DISTINCT” right after SELECT clause.

SELECT DISTINCT [Column 1], [Column 2]
FROM [Table];

and the result will be unique combinations of columns

Example of extracting unique records from SQL table

Source table looks like this:


Let’s try to extract unique records from field TerritoryCountry. There are duplicities in this field because 1 country (SalesTerritoryCountry)  can have multiple regions (SalesTerritoryRegion). However, we are interested in unique values.

SELECT DISTINCT [SalesTerritoryCountry]
FROM [AdventureWorksDW2012].[dbo].[DimSalesTerritory]
ORDER BY [SalesTerritoryCountry];

We get this table as required:  

Select distinct priklad

Rate this post
Category: SQL Clauses Tags:

About Jan Zedníček

My name is Jan Zedníček and I work as a freelancer. I have been working as a freelancer for many companies for more than 5 years. I used to work as a financial controller, analyst and manager at many different companies in field of banking and manufacturing. When I am not at work, I like playing volleyball, chess, doing a workout in the gym and I enjoy tasting of best quality rums. I am trying to summarize all my knowledge on this website not to forget them (because of the rum effect, you know =) and to put them forward to anyone. Don´t worry about asking for help or writing some comments.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.