Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
No Duplicates
Message
De
30/04/2010 18:08:53
 
 
À
30/04/2010 14:23:59
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Divers
Thread ID:
01462570
Message ID:
01462601
Vues:
45
>Hello All!1
>i have this table that has dupllicates and i want to delete all the duplicatates an be only left with one oof the duplicated record. During that time i realized i dint know an SQL that could say that so decided to do an sql using the no duplicated. but then that only works for indexed records an will not work for everything in a TAble. So is there another way i can express what i want to the DAtabase?

All the following is based on the assumption you are working with VFP tables. If that's not true, feel free to ignore....

Are the records complete duplicates in that ALL fields in the record are the same? If so, then something like
SELECT DISTINCT * FROM myTable INTO CURSOR myCursor NOFILTER
DELETE FROM myTable
INSERT INTO myTable SELECT * FROM myCursor
The old records will still be hanging around marked for deletion and you will need to PACK the table to make them disappear.

If it's only a subset of fields that mark the records as duplicates then you might try something like
SELECT *, 000000 as idrec FROM myTable INTO CURSOR crsTemp READWRITE
REPLACE ALL idrec WITH RECNO()
SELECT <dup field list>,MIN(idRec) AS idRec FROM crsTemp GROUP BY <dup field list> INTO CURSOR crsDUPS
SELECT crsTemp.* FROM crsTemp JOIN crsDups ON crsTemp.idrec = crsDups.idrec INTO CURSOR crsAppend NOFILTER
SELECT myTable
DELETE ALL
APPEND FROM DBF('crsAppend')
It's not the most "modern" of code, but I think it should work for you. (or at least get you started)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform