Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Get 1st record if duplicate records found?
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00575370
Message ID:
00575404
Vues:
26
>You can do this in two selects
>SELECT field1, field2 , RECNO() AS rn ;
>	FROM test2 ;
>	INTO CURSOR temp1
>
>SELECT field1, field2 ;
>	FROM temp1 ;
>	WHERE field1 + STR(rn) IN ( ;
>		SELECT field1 + STR(MIN(rn)) ;
>			FROM temp1 GROUP BY field1)
>
>

These selects would not filter duplicates only. You should modify the second select into :
SELECT field1, MIN(rn) as rn, count(*) as cntDups ;
			FROM temp1 GROUP BY field1 ;
                        having cntDups>1 ;
                        into cursor temp2

SELECT field1, field2 ;
	FROM temp1 ;
	WHERE field1 + STR(rn) IN  ;
		(SELECT field1 + STR(rn) ;
			FROM temp2)
>>field1,field2
>>abarca,2243
>>abarca,3314
>>abarca,2142
>>
>>I need to get the 1st record: abarca, 2243.
>>SELECT * from table1 GROUP BY field1: returns the last record (abarca, 2142).
>>What would be the correct SQL statement to do so?
>>
>>Thank you all!
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform