Solved

Deleting Dulpicate row

Posted on 2001-09-10
8
264 Views
Last Modified: 2008-02-07
Dear All,
Is there Any query ,Which will Delete Duplicate Rows from the table which does not  have primary key..please
Help me out
0
Comment
Question by:skumaravelan
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 1

Expert Comment

by:whbram
Comment Utility
What database are you using?
0
 
LVL 1

Accepted Solution

by:
kdg2000 earned 50 total points
Comment Utility
Algorithm 1:
1. Opens Recordset of all unique values
2. In cycle there is an exhaustive search of all values.
3. In cycle: We define how many counterparts of current value in the table. If them more than 1, then is remembered current value, we delete all and is added it(him).
4. End of cycle
5. Closing RecordSet.

Algorithm 2:
1. Opens Recordset of all values sorted on increase
2. We create a variable, in which the previous value is stored
2. In cycle there is an exhaustive search of all values.
3. In cycle: whether We define equally given data previous. If yes - then is deleted it, differently - variable is assigned current value
4. End of cycle
5. Closing RecordSet.

In SQL Server it is done(made) so:

declare @S as varchar (8000)
/* The cursor of the necessary type */ is declared
declare Data_Pr_F scroll cursor
/* Choice of not repeating values */
for select distinct DuplicateRows from [table]
open Data_Pr_F
FETCH FIRST from Data_Pr_F into @S
      /* Check of the end of the table */
      while @@ fetch_status < > -1
      begin
           /* If there is more than one counterpart, then all values are deleted and one unique value is added */
           if (select count (DuplicateRows) from [table]) > 1
           begin
                delete * from [table] where DuplicateRows = S
                insert into [table] values (@S)
           end
           /* Transition to the following string(line) */
           FETCH next from Data_Pr_F into @S
      end
/* Deleting the cursor */
DEALLOCATE Data_Pr_F
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
maybe also

step one: create a table with none duplicate values
  create table tmp as Select distinct * from originaltable;

step two: empty sourcetable
  delete from originaltable;

step three: store back
  insert into originaltable select * from tmp;

step four: drop tmp-table
  drop table tmp;


(may not work on all databases)

meikl ;-)
0
 

Author Comment

by:skumaravelan
Comment Utility
Dear All,
I have tried al the option u all said befoe.My question is,is there any way to do the same with writing a procedure or function
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
it would help,
if you let us know the database you have
0
 

Author Comment

by:skumaravelan
Comment Utility
Hi kretzschmar,
I have oracle 8 as my database.
0
 
LVL 1

Expert Comment

by:kdg2000
Comment Utility
Oracle 8 is very similar on MS SQL Server. Some finishings are certainly necessary. For example environment variable @@ fetch_status for certain is not present in Oracle, but 100 % there are a similar variable. Anyway standard SQL 92 is uniform both for Oracle and for MS SQL Server.
I think these small finishings as you seem to me can make.
0
 

Author Comment

by:skumaravelan
Comment Utility
Dear KDq2000,
Thank You very much for ur valuable reply.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now