Home > DeveloperSection > Forums > Select unique record from table
Mark Devid
Mark Devid

Total Post:101

Points:707
Posted on    January-07-2013 5:44 AM

 MSSQL Server MSSQL Server 
Ratings:


 1 Reply(s)
 1243  View(s)
Rate this:
Hi every one

I have a table witch have duplicate records. I want to select only unique record with how many time repeated  form table.
My table structure as

CREATE TABLE [dbo].[EmpInfo]
(
  [ID] INT IDENTITY PRIMARY KEY,
  [EmpName] VARCHAR(100)
)

INSERT INTO [dbo].[EmpInfo]  ([EmpName]) VALUES('Chris Roberts')
INSERT INTO [dbo].[EmpInfo]  ([EmpName]) VALUES ('Brad Tutterow')
INSERT INTO [dbo].[EmpInfo]  ([EmpName]) VALUES('Chris Roberts')
INSERT INTO [dbo].[EmpInfo]  ([EmpName]) VALUES ('Brad Tutterow')
INSERT INTO [dbo].[EmpInfo]  ([EmpName]) VALUES ('Paul Mendoza')
INSERT INTO [dbo].[EmpInfo]  ([EmpName]) VALUES ('Zack Peterson')
INSERT INTO [dbo].[EmpInfo]  ([EmpName]) VALUES ('Paul Mendoza')
INSERT INTO [dbo].[EmpInfo]  ([EmpName]) VALUES ('Zack Peterson')
INSERT INTO [dbo].[EmpInfo]  ([EmpName]) VALUES ('Vijay Shukla')

Thank in advance


AVADHESH PATEL

Total Post:604

Points:4228
Posted on    January-07-2013 8:01 AM

Hi Mark Devid,

you can use below sql query

SELECT [EmpName], COUNT(*) TotalCount FROM [dbo].[EmpInfo]  GROUP BY [EmpName] HAVING COUNT(*) > 1 ORDER BY COUNT(*) DESC

Don't want to miss updates? Please click the below button!

Follow MindStick