Learn
When we are examining data in a table, it can be helpful to know what distinct values exist in a particular column.
DISTINCT
is used to return unique values in the output. It filters out all duplicate values in the specified column(s).
For instance,
SELECT tools FROM inventory;
might produce:
tools |
---|
Hammer |
Nails |
Nails |
Nails |
By adding DISTINCT
before the column name,
SELECT DISTINCT tools FROM inventory;
the result would now be:
tools |
---|
Hammer |
Nails |
Filtering the results of a query is an important skill in SQL. It is easier to see the different possible genre
s in the movie
table after the data has been filtered than to scan every row in the table.
Instructions
1.
Let’s try it out. In the code editor, type:
SELECT DISTINCT genre FROM movies;
What are the unique genres?
2.
Now, change the code so we return the unique values of the year
column instead.
Take this course for free
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.