User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 426,187 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,827 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser: Programming Forums
Views: 15291 | Replies: 12 | Solved
Reply
Join Date: Nov 2007
Posts: 31
Reputation: puneetkay is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
puneetkay's Avatar
puneetkay puneetkay is offline Offline
Light Poster

Re: how to delete duplicate record in a table by using SQL query

  #11  
Mar 6th, 2008
Well guys.. im new for MS SQL.. i have a solution & it worked perfectly with me.

while creating table just add an extra attribute using identity keyword:
attributename int identity(1,1)
so everytime you insert any row, it will increase 1. so there will a unique number for every row

Regards!
Last edited by puneetkay : Mar 6th, 2008 at 6:36 am.
Reply With Quote  
Join Date: Nov 2007
Location: � Jogja �
Posts: 2,584
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Rep Power: 11
Solved Threads: 235
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: how to delete duplicate record in a table by using SQL query

  #12  
Mar 6th, 2008
  1. DELETE FROM emp e WHERE rowid>(SELECT MIN(ROWID) FROM emp WHERE e.empno=empno)
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote  
Join Date: Mar 2008
Location: Holland
Posts: 9
Reputation: space1000 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
space1000 space1000 is offline Offline
Newbie Poster

Re: how to delete duplicate record in a table by using SQL query

  #13  
Mar 7th, 2008
Just solve the thing with a cursor

like
declare del_dups cursor
for
select * from <table_name>
group by column_name
having count(*) > 1

(column_name where the duplicates are)

open del_dups

fetch next from del_dups into ......

while @@fetch_status <> 0
begin
delete from table_name where current of cursor
fetch next from del_dups into ....
end

close del_dups
deallocate del_dups

For the update you should change te delete statement to

update table_name set ... = .... where current of cursor
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MS SQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the MS SQL Forum

All times are GMT -4. The time now is 6:41 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC