Distinct statement is an SQL statement that is used to show only one of several identical records in a table.
Let’s reinforce it with an example.
First, let’s create our table named distinctörneği.
1 |
create table distinctörneği (id serial, adi text,soyadi text ) |
Let’s add a record to the distinct table we created.
1 2 3 4 5 6 7 |
insert into distinctörneği(adi,soyadi) values('faruk','ERDEM') insert into distinctörneği(adi,soyadi) values('utku','AYDIN') insert into distinctörneği(adi,soyadi) values('ufuk','ZEKİ') insert into distinctörneği(adi,soyadi) values('faruk','ERDEM') |
Let’s display the columns in our table by selecting the name column.
As seen above, faruk record has been added twice in our table, and we will ensure that the same record is received only one of them with the distinct command.
As seen in the example above, we are listing only one of the faruk records in our table.