SELECT UNIQUE RECORD FROM TABLE

Mark Devid

Total Post:102

Points:714
Posted by  Mark Devid
 1594  View(s)
Ratings:
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
  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Select unique record from table

    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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!