why we are using distinct keyword in sql server?

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

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


then
select distinct EmpName from emp
then it displays
only
EmpName
Aswini A
Aluri


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: 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