why we are using distinct keyword in sql server?

 Posted by aswinialuri-19361 on 3/27/2013 | Category: Sql Server Interview questions | Views: 4782 | Points: 40

The DISTINCT keyword in SQL allows you to select only those records that contain unique values for the columns requested in a SELECT statement. Duplicate values are ignored and only displayed once.
Ex:- using emp table
Emp ID EmpName
1 Aswini A
2 Aswini A
3 Aluri

select distinct EmpName from emp
then it displays
Aswini A

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Pandians on: 3/28/2013 | Points: 10
DISTINCT also SORT the data!
Posted by: Jitendrasoft09 on: 3/28/2013 | Points: 10
When we will use single column for distinct it is ok, but If we will use multiple column with function then we have to use the group by clause, freely we can use the gruop by clause to get the unique value without consider in which column function is used or not. for performance wise distinct is slow then group by clause as good thing is distinct sort the data by default.
Posted by: Lastword on: 3/28/2013 | Points: 10
It retrives only unique values from database. Like there is colun in your database "EmpName ". And there are so many duplicate records in this column. Then this 'distinct ' keyword display the repeated records only once with other records.
Posted by: Peeyushkumar2 on: 3/30/2013 | Points: 10
if table contains same or unique value in more than one row then we use distinct keyword to select single row from the table.

Login to post response