Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following table and data as follows:
SQL
sno	name	city
1	simbu	bangalore
1	simbu	bangalore
1	simbu	bangalore
1	simbu	bangalore
1	simbu	bangalore
1	simbu	bangalore

now i have to remove the duplicates . how can i accomplish this? the thing is i have not included any primary key. without primary key concept i have to remove duplicates how can i do tat? out of those 6 rows 1 row should remain finally after removing the duplicates. Now can any 1 tell me how can i perform the above operation using ranking functions?
Posted
Updated 1-Sep-13 18:32pm
v3
Comments
Garth J Lancaster 30-Aug-13 6:56am    
is this exactely the data, or just an example ?
Prakash Thirumoorthy 30-Aug-13 6:57am    
do u want to remove from the table? or do u want to remove the duplicate values and show the different values only in result set?
ARUN K P 30-Aug-13 7:11am    
that s the data. and i want to delete all the duplicate values and preserve the result set in the same table.
Prakash Thirumoorthy 30-Aug-13 7:15am    
i have given answer. check that. it will may help u and solve ur problem.
ARUN K P 30-Aug-13 7:29am    
yeah sure :)

Remove Duplicate Rows from a Table in SQL Server[^]

You can check this...it will help you..
 
Share this answer
 
Comments
ARUN K P 30-Aug-13 7:00am    
No i don wanna do it in that way. i know that way. is there any way to delete the duplicate without alteting the table?
You could try something like this, assuming your data is in a table called mytable;
SQL
select distinct * into #mytemptable from mytable
truncate table mytable
insert into mytable select * from #mytemptable
drop table #mytemptable


Hope this helps,
Fredrik
 
Share this answer
 
Comments
ARUN K P 30-Aug-13 7:30am    
thanks
Fredrik Bornander 30-Aug-13 7:49am    
Glad I could help.
Thanks7872 30-Aug-13 7:31am    
Smarter way to stay fit..:laugh: Upvoted..!!!
 
Share this answer
 
Comments
ARUN K P 30-Aug-13 7:30am    
thanks
Thanks7872 30-Aug-13 7:32am    
You are welcome. Accept the most relevant solutions only. Always.
Hi,
you can do it by using temporary table.

SQL
create table #temp (Sno int, Name varchar(50),  City varchar(50))
insert into #temp select * from Maintable

delete from Maintable

insert into Maintable select distinct * from #Temp


select * from Maintable

drop table #temp


Regards,
Prakash.T
 
Share this answer
 
Comments
ARUN K P 30-Aug-13 7:15am    
Thanks its working fine . +5
Prakash Thirumoorthy 30-Aug-13 7:16am    
yeah! welcome..
Herman<T>.Instance 30-Aug-13 7:18am    
bad practice. what happens if inserting to #temp fails?

You can use row_number() over(fields order by fields) fucntionality to find doubles in a table
ARUN K P 30-Aug-13 7:30am    
ok fine will try tat way too

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