Sql Server Remove Duplicate Value From a Table

How to Remove Duplicate Value From a Table

If We have a table like following and we need to remove Duplicate Value

ID FNAME LNAME
1 AAA CCC
2 BBB DDD
1 AAA CCC
2 BBB DDD
1 AAA CCC
2 BBB DDD
3 BCB DGD

If we want to remove duplicate value from above table
Than we can use following Query

SELECT DISTINCT * INTO NEWTABLE FROM OLDTABLE
TRUNCATE TABLE OLDTABLE
INSERT INTO OLDTABLE SELECT * FROM NEWTABLE

Sql Server Remove Duplicate Value From a Table

Sql Server Count Duplicate Records – Rows

Count Duplicate Records – Rows

If We have a table like following and we need to find No of Duplicate column than follow 

1	AAA	CCC
2	BBB	CCC
2	BBB	DDD
3	CCC	DDD
3	CCC	DDD
3	CCC	DDD
1	AAA	CCC
1	AAA	CCC
1	AAA	CCC
1	AAA	CCC
2	BBB	DDD
2	BBB	DDD


If You want to Count Duplicate Values in Column 

SELECT ID , COUNT (*) AS COUNTMULIPLE FROM SAMPLE 
GROUP BY ID 
HAVING COUNT(*) > 1