Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
In the last video, we learned how to retrieve data from a table.
But when we were retrieving the data, all the data from the table was coming.
And even if our table had duplicate values, say, for example, if two or more customers had the same
first name, it would have appeared multiple times.
So to get rid of these duplicate values and to get only unique value, we need to use the distinct keyword
with the select command.
Distinct keyword will eliminate all the duplicate records and it will fetch only unique records.
This is the syntax for distinct command.
Select this thing.
Mention the column names one or more and then write the keyword from and mention the table name.
Let us see an example.
To retrieve only a single column with customer's first name.
We will select distinct customer first name from the customer table.
To get multiple columns, we will write first name and age and get it from the customer table.
Let us go and write this in dpkg admin window.
Right now.
If I do select start from customer table if I run the last query.
So overall, there is no duplicate value in our table.
But if you look at only the first name column, there is a g value three times out of which to have
the same case, and the third one has a different case.
So if I want to get only the unique first names.
I'll write.
I'll need to use the distinct keyword.
Let us write.
Select, distinct.
First name.
From.
The customer table.
Take a moment to guess what will be the result of this query.
And now let us run this query.
So did you get it correctly?
It is giving us only six values back.
Two of the duplicate values have been removed.
You can see there are two different genes still in the retrieved data.
But these two are different in their case.
That is why both these are present in the data.
So let us compare this with the select query without the distinct keyword.
This will make it easier to compare.
You can see there are eight entries in the first name.
There were two GS and two JS.
One of the J has been removed and one of the G has been removed.
So that is how.
Distinct keyword helps us identify the unique value while retrieving the data.
Now let us try to retrieve more than one column from the database.
We will select distinct first name.
And age.
From the customer table.
And then this query.
We get only the distinct values back.
Let us see what happens if we run select distinct star.
Customer table.
Gun.
So you can see the fifth and seventh record have all the value same except the customer ID.
Due to this mismatch of customer ID select distinct was not able to remove this duplicate value.
It removes only exact duplicate rows.
So let us see by adding an exact duplicate row.
We will rerun the copy statement from above.
This will add the two rows again.
We will run a select start statement once to see if the.
Two entries are added.
You can see we now have two more entries, and these two entries are exactly same.
So the fifth and six entry and the nine and ten and three are exactly same.
Now let us do select distinct start on the customer table.
The two new records that we added, which are exactly similar to the earlier ones, will now be removed.
Those will not be retrieved.
So you see, we have eight records now.
So that is all with the distinct keyword.
So in this video, we learned how to get unique data retrieved from the database.
So see you in the next lecture.
In the next video we will cover the web command, which is used to filter out the unwanted data from
the retrieved data.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.