1.To select distinct result for a specific column, we use the command:
select distinct(col1) from table1;
For example: select distinct(studentid) from student;
2.If we want to select distinct with more than one column, we can use the command:
select distinct col1, col2, col3 from table1;
For example: select distinct studentid, name, address from student;
3.If in a VIEW, for some reasons, contain duplicate rows. It means that there are rows that 100% match to each other in a View. If we want the select command to show duplicate rows just one time, we can use the command:
select distinct * from table1;
The command will let duplicate rows shown only one time.
4.If we have a TABLE, and this table contain duplicate rows. And, we want to delete duplicate rows by some of criteria columns, we can use the command:
DELETE FROM T_TB1 WHERE rowid not in (SELECT MIN(rowid) FROM T_TB1 GROUP BY C_C1, C_C2, C_C3);
***C_C1, C_C2, C_C3: list of columns that form a criteria/condition
More Info ……..
5.If we join two tables in a select command, and in the results contain duplicate rows. If we want to refine the result with a distinct column as criteria only, we can use the command:
select distinct(table1.column1), table2.* from table1, table2 where table1.column2=table2.column3;