I welcome you back again to the virtual PostgreSQL.
And here let's go ahead and learn about the keyword distinct.
So what's the first thing like.
What is distinct.
And it's very important aspect in PostgreSQL or in SQL queries.
Now you might have things like uh, let me say I want to select, uh, let me go ahead and select oh.
I want to select, uh, all brown students or let me go ahead and select country.
I want to start country from students.
And if I go over here you can see I have a Russia, I have China, Russia, Thailand.
And uh, if you go down here, you can see I have Indonesia and I have Indonesia, and I have Philippines,
I have Philippines and Philippines.
Now, remember, if you go down on this, you can continue to open up all this.
What?
I really love working over here.
So if I go ahead and select country over here.
Go ahead and select country and load this year.
I have all this.
And I can select most of these numbers for which most times I have China and I have China.
And now I just want to select I want some of the countries that are here.
I just want to know them by one.
Like say China, then Poland, Indonesia, Philippines, Bulgaria, whatever.
Again.
Then Portuguese without repeating China, uh Philippines and uh, Czech Republic.
So how can I be able to do that?
So if I go ahead and say select a country from students and, uh, I see order, order by the country
with a semicolon at the end and run this thing, you can see that this actually arranged this from Afghanistan
down to Albania, Argentina.
And if I scroll this down, let's go ahead and check it out.
And I have Yemen.
I have total of 1000 rules.
And consider Yemen repeated many times and Vietnam repeated many times.
Yes, because these are assigned to some of these rules or all of the rules.
But I just want to know only.
I just want to know the numbers of the countries and the distinct numbers and the countries that are
inside this data set.
So the way to do that is, uh, by using that keyword distinct, and I want to use the keyword distinct.
All I need to do is I have to say select.
And then I'll go ahead and insert distinct.
So if I should put those distinct country, it means I want to select just one out of control repeated.
Just one out of the countries are repeated to show the countries that are all in here.
And if I run this query let's check it out.
You can see you have Afghanistan, just one Albania, one American Samoa.
Samoa or Angola?
Argentina.
Armenia, Australia and so on.
And if I should go right down here, I have Yemen and Vietnam and have a row of modern 24 of 124 and
something is applicable to, let me say first underscore name.
And if you select that from first underscore name.
And when I say first underscore name.
And if I run this first and check it out, you see we have rules of 941 instead of 1000, because there
are names that are actually repeated by the Serbs.
And that is applicable to all of these.
And you can also arrange these in alphabetical order.
So this actually starting from alphabetical order.
And if you want that to start from descending order, all I need to do is I'll go ahead and add this
keyword descend.
And if I run this it's going to start from the last zero.
And that is applicable to countries as well.
You can also do that for dates if you go ahead and check dates.
So we want to see dates underscore all that is in rule.
Deeds in rule.
Underscore dates.
And then I have to change this to in rule.
Underscore dates.
And let's go ahead and execute the query.
And uh we have 2050 1010 2050 uh 1007 both are different.
And we have a total rule of guitar and 64 of 864.
So the distinct value helps you to distinguish between repeated numbers of our data in a row and in
a table.
You actually get only one out of repeated values.
How that is cool.
So go ahead and apply this check it out program with it, and if you have any question, go ahead and
use the question and answer section.
And I'm going to get back to you as soon as possible.
Thank you so much.
And I'm going to see you in the next video lecture.