[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Deleting Dulpicate row

Posted on 2001-09-10
8
Medium Priority
?
278 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 1

Expert Comment

by:whbram
ID: 6473197
What database are you using?
0
 
LVL 1

Accepted Solution

by:
kdg2000 earned 200 total points
ID: 6473256
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
ID: 6473756
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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

Author Comment

by:skumaravelan
ID: 6473771
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
 
LVL 27

Expert Comment

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

Author Comment

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

Expert Comment

by:kdg2000
ID: 6475728
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
ID: 6475813
Dear KDq2000,
Thank You very much for ur valuable reply.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

656 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