Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Get 1st record if duplicate records found?
Message
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00575370
Message ID:
00575406
Views:
21
There was no request to filter out none duplicates.

>>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!
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform