19 April 2014

Count duplicate records or rows in SQL Server



create table tbl_names(Id int identity(100,1),Name varchar(100))

insert into tbl_names values('adi')
insert into tbl_names values('adi')
insert into tbl_names values('adi')
insert into tbl_names values('adi')

insert into tbl_names values('raja')
insert into tbl_names values('raja')

insert into tbl_names values('nani')

insert into tbl_names values('balu')
insert into tbl_names values('balu')

insert into tbl_names values('pavan')

insert into tbl_names values('abcd')
insert into tbl_names values('abcd')


SELECT Name, COUNT(*) TotalCount FROM tbl_names GROUP BY Name HAVING COUNT(*) > 1

No comments:

Post a Comment