Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Deleting Duplicate Records In Table
Message
De
12/04/2013 14:29:41
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP
Network:
Windows XP
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01570796
Message ID:
01570832
Vues:
55
>>Using the following code I could Get the number of counts for Duplicate records. But How do I delete the Duplicate entries, i.e I just want to keep the one single entry for my account Number, Preferebly the last one.
>>
>>
>>SELECT Accountno As Account_No,COUNT( * ) AS DupCount;
>>  FROM New_master ;
>>  INTO CURSOR Duplicates ;
>>  GROUP BY Accountno ;
>>  HAVING DupCount > 1 
>>
>>
>>I tried Select * from New_master UNION Select * from New_master . But It didn't worked.
>
>From the top of my head
>
>delete NM from New_Master NM ;
>where exists (select 1 from (SELECT Accountno As Account_No,COUNT( * ) AS DupCount, MAX(AccountDate) as LastDate ;
>  FROM New_master ;
>  GROUP BY Accountno ;
>  HAVING DupCount > 1)  X where X.Account_No = NM.AccountNo and NM.AccountDate < X.LastDate)
---
Thanks Madam, but by last added I does not mean that I have a Accountdate field in may be used to get the last updated accountno in my table. By last added I mean to say the Accountno which was addaed at the last i.e Max recno(). I dont have accountdate field in my table.
Kinldy reinstiate the SQL, if you could please.

By the time I have used this code to delete Duplicate entries. Does SQL works faster than the below code. ?
SELECT Accountno As Account_No,COUNT( * ) AS DupCount;
  FROM New_Master ;
  INTO CURSOR Duplicates ;
  GROUP BY Accountno ;
  HAVING DupCount > 1 
IF Dupcount>1
SELECT Duplicates
SCAN
FOR I=1 TO (DUPCOUNT-1)
DupAccount_no=Account_no
SELECT New_master
LOCATE FOR Accountno=DupAccount_no
DELETE
SELECT Duplicates
ENDFOR
SELECT New_master
ENDSCAN
USE IN Duplicates
ENDIF
Harsh
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform