Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Selecting 10 records randomly
Message
De
04/01/1998 00:07:56
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00069291
Message ID:
00069298
Vues:
39
>>>>What would be the best technique to select 10 records randomly from a table?
>>>Michel, do you mean by RECNO() ?
>>
>>I have a set of 250 records. Depending on the SQL, I may have a total of 135 records approx. for the SQL result set. From those, I would like to select 10 records randomly.
>>
>>I tried various techniques but I don't like them. I figured their must be something better.
>
>I always used just basic
>=rand(-1)
>x=rand()
>and then make a value from X some way, corresponding the necessary range.

Yes, but the random need to be taken from existing records.

Let suppose I have 135 records in my cursor. I can GO BOTTOM to have my random value. In this case, the value is 135. So, I need to execute the random 10 times and to GO to the cursor record RECNO() from the random value to get my unique key so I can construct my final SQL. I also need to make sure I don't choose the same record twice.

When I have my 10 values, I can then to the final SQL with a WHERE INLIST(uniquekey,value1,value2,value3...).

This is what I was wondering is something better can be done.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform