How to select distinct data from Database?

Asked 14-Sep-2021
Viewed 549 times

1 Answer


0

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.
Syntax –
        SELECT DISTINCT column1,column2,column3,…. FROM table_name ;
Example :
    Lets have a Database table 'Orders'-
            How to select distinct data from Database?

The following SQL Statement is select distinct OrderFrom from 'Orders' table.
    select distinct OrderFrom from Orders; 
            How to select distinct data from Database?
Select multiple distinct columns from 'Orders' table.
    select distinct OrderName, OrderFrom ,Id from Orders;
        How to select distinct data from Database?
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; 
            How to select distinct data from Database?