Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to Remove duplicate data From table in sqlserver table

My table Data :
ID       Name
344B6794 Visal
CA6B5B10 Raghu
9DC012F7 Visal
FDC12AC1 Raghu
9B439B6F Rakesh
F9F7D96A Naresh
A28909C3 Rakesh


I need to get below data only
ID       Name
344B6794 Visal
CA6B5B10 Raghu
9B439B6F Rakesh
F9F7D96A Naresh


How can i get the data...?
Could any one know about this Reply me ?

Regards
Kishore
Posted
Updated 14-May-13 3:10am
v2
Comments
Yuriy Loginov 14-May-13 8:43am    
there are no duplicates in the data because the ID is different. For example
{344B6794 Visal} is not the same as {9DC012F7 Visal}
nandkishorre 14-May-13 8:50am    
Ya.. but i need names. Here names are repeated.
Maciej Los 14-May-13 9:14am    
Based on which criteria?
nandkishorre 14-May-13 9:18am    
Based on Name bind only name and id

Try this one ..
SELECT Name, MAX(ID) FROM tablename
GROUP BY Name
 
Share this answer
 
This link should help you.

Click Here
 
Share this answer
 
v2
well in your case there is no duplicate data in table,
but if you consider only names as duplicate data then you can get distinct data in following ways...

SQL
select MIN(ID), Name from tbl_1
group by Name

or
SQL
select MAX(ID), Name from tbl_1
group by Name


choose any of above according to your requirement.

hope it will help.
 
Share this answer
 
v2
Maciej Los - wrote:
Based on which criteria?

nandkishorre - wrote:
Based on Name bind only name and id


It's not possible, because names are duplicated, but id's not!
ID Name
344B6794 Visal is not equal to 9DC012F7 Visal
CA6B5B10 Raghu is not equal to FDC12AC1 Raghu
9B439B6F Rakesh is not equal to A28909C3 Rakesh

Till id's are differ, records are not equal!

NOTE:
If you remove any "duplicate data" (in your mind) and your data are related with other, you'll lose relationships between data.
 
Share this answer
 
v2
Comments
nandkishorre 14-May-13 9:40am    
I got Answer
nandkishorre 14-May-13 9:42am    
Thank u For your Response
SQL
select ID,Name  from Table1 as A where ID     = ( select top1 ID           from Table1          where Name= A.Name)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900