Lesson 12: Removing duplicates from results with the DISTINCT keyword.

By Alan Hylands — 1 minute read

Duplicates in data tables are a fact of life.

They can cause serious issues when performing calculations or counts if not properly de-duped. We can do this in the SELECT statement by using the DISTINCT keyword. This means only one "distinct" data row is returned for each combination of columns in our statement.

For example,

SELECT DISTINCT Surname 
FROM PlayerNames;

This would mean that no matter how many times a particular surname appeared in the "Surname" column of our table, our results would only bring it back ONCE.

Duplicates be gone.

Quiz Time.

The Question.

Oh oh. ICE are at the door of the Avengers Tower and they want to see some paperwork.

How would we get a DISTINCT list of of the different nationalities of the characters in our table?

The Data.

The Editor.


Run SQL


Show Answer

The Answer.

Correct SQL:

                    SELECT DISTINCT nationality FROM characters;
                    

Correct Output:

Try the next lesson