Select Distinct Statement-
Select Distinct data from table-
This SQL statement used to retrieve distinct(different) values. Sometimes a database table contains many duplicated value and if we want to retrieve all duplicated values in single form then we can use this SQL statement. It returns all different values from table.
SELECT DISTINCT column1,column2,column3,…. FROM table_name ;
Lets have a Database table 'Orders'-
The following SQL Statement is select distinct OrderFrom from 'Orders' table.
select distinct OrderFrom from Orders;
Select multiple distinct columns from 'Orders' table.
select distinct OrderName, OrderFrom ,Id from Orders;
The following SQL statement is lists the number of different Id in Orders table-
This statement will returns the number of different column data from database table.
select count( distinct Id) from Orders;