i have a table with huge data i need to remove duplicates from that table

when i am using this query i am getting different set SELECT Gender,GivenName,Surname, COUNT(*) AS NO_OF_DUPLICATE_RECORDS FROM HugeNames where NameID is not nullGROUP BY Gender,GivenName,SurnameHAVING COUNT(*) > 1

after writing CTE :

;WITH cteas( SELECT GivenName, Surname,MiddleInitial FROM HugeNames WHERE rtrim(ltrim(GivenName)) like '%%' AND NameID is not null AND ltrim(rtrim(Surname)) like '%%' and GivenName is not null and Surname is not null GROUP BY GivenName, Surname,MiddleInitial HAVING COUNT(*) > 1 ) SELECT u.GivenName,u.Surname,NameID,u.MiddleInitial from HugeNames u

INNER JOIN cte ON u.GivenName=cte.GivenName AND u.Surname=cte.Surname AND u.MiddleInitial=cte.MiddleInitial where u.GivenName is not null AND u.Surname is not null AND u.MiddleInitial is not nullORDER BY GivenName,Surname,MiddleInitial ASC