Categories
Sql Server

How to select Distinct records from a table in Sql server

In tables some of the columns may contain duplicate values. But you want to list out the (distinct) values of a coloum in that table.

The DISTINCT keyword can be used to return only distinct (different) values.

First of all create a table.

create table dept_test( Deptno int,dname varchar(20),loc varchar(20))

Then insert records into the table you created .

insert into dept_test values(10,’it’,’haryana’)

insert into dept_test values(20,’hr’,’Delhi’)

insert into dept_test values(10,’admin’,’agra’)

insert into dept_test values(40,’canteen’,’Delhi’)

insert into dept_test values(60,’house keeping’,’Delhi’)

insert into dept_test values(70,’it’,’Delhi’)

insertinto dept_test values(30,’hr’,’kolkata’)

Then select records from your table.

Select * from dept_test

go

Select Distinct dname from dept_test

      click on image to enlarge