All Type Coding

Search Here

Distinct Statement in sql server.


Distinct Statement
                                                   The  DISTINCT command is used in conjunction with SELECT statement to remove all the duplicate records and fetching only unique records.or we can say that The DISTINCT statement is used to return only different values.but sometime a column may contain many duplicate values but you want only different value.

Syntax:
              Select Distinct Col1,Col2,Col3 from table_name

Here we will see an example of Distinct statement.we have a table Employee1 for this demo

















Now we'll use the distinct statement The above table contain the duplicate data ,like Name,salary and gender but we need to unique or different data from the given table.For getting unique data execute below query on sql query window

                Select Distinct Name,Gender,salary from Employee1
after executing the above query output will be
            

















The above given table contain 7 record but after using the distinct statement we get only 4 record.Thus distinct statement is very helpful to remove dulicate data and  fetching unique or different data from the database  table.



















No comments :

Post a Comment