SELECT DISTINCT Statement
- 01:20
What is the SELECT DISTINCT Statement
Downloads
No associated resources to download.
Transcript
The select distinct statement is only used when you have multiple duplicate values in your database.
So the select distinct statement essentially returns only the different values from the database IE, the unique values from the data.
If the table contains duplicate values, then the statement just returns distinct values.
But how do we write a select distinct statement? So essentially, because it's a select distinct statement, it starts with a select distinct, just like the select statement.
It then follows by the columns that we require.
And then once we specify our columns, we determine the table from which we want the data from.
So that's going to follow the from statement.
So we have the select distinct, the columns, the from and the table name, and then the whole statement ends with the semicolon.
And once we run this, it's gonna return us the desired values.
If we want to have a count of the data, we use the count distinct rather than the plain distinct.
So let's say that we have a share price data set with multiple tickers and different values in case we have duplicate values in the data, we essentially use the select distinct statement with the group desired columns and the table name.