SQL DISTINCT
Summary: In this tutorial, you will learn how to use SQL DISTINCT along with SQL SELECT statement to eliminate duplicate records.
SQL DISTINCT is used to eliminate the duplicate rows in the result set of SELECT statement.
For example, to get all the cities of employees you can use SELECT statement as follows:
SELECT city
FROM employees

As you see, you get the result with the duplicate cities that you may not expect. The duplicate city give you the information that some employees live in the same city.
To remove the duplicate cities, you can use DISTINCT keyword after SELECT keyword in the SELECT statement as follows:
SELECT DISTINCT city
FROM employees

Now we have a list of cities that employee are living in without duplicate values.
It is important to note that the DISTINCT keyword is used before a column name to filter duplicate values of that column. The duplicate is evalued based on column's value. In this case, city is the column where the evaluation takes place.
If you put multiple column after the DISTINCTkeyword, the combination of those columns will be used to evaluate the duplicate. For instance, if you want to know all cities and countries where employees live, you can perform the following query:
SELECT DISTINCT city, country
FROM employees

In the query above, the combination of city and country is used to determine the uniqueness of record in the result set.
Beside DISTINCT keyword, you can use ALL keyword to indicate that you don’t want to eliminate duplicate records. Because ALL keyword is default in the SELECT statement so you don’t have to specify it explicitly.
In this tutorial, you've learned how to use DISTINCT keyword in SQL SELECT statement to eliminate duplicate records in the result set.
Related Tutorials
How to use SQL Distinct correctly? come here to read SQL Distinct tutorial with examples, you will learn how to use SQL distinct in various examples.
Basically you can use SQL Distinct to eliminate duplicate rows.