I need some help getting random results in a query.
I have this so far, and it works, but it is slow.
SELECT TOP 1 tblMain.Field1, tblMain.Field2, Rnd(tblMain.Field2) As Expr1, ... FROM tblMain WHERE tblMain.COMPLETED=False ORDER BY Rnd(tblMain.Field2) DESC;
This does a great job actually finding a random record.
The problem is that it is slow. I have about 77,000 records currently. I will need to add I would say at least another 250,000 records to this database. So the speed will be very slow.
Is there a way to just get a quick query of say 100 records, then run the randomize query on just those records in order to choose one?
Or could I use an autonumber field set to random and have it somehow grab one of those?
My issue is that a form I have for working on these grabs one, but if I just use the TOP 1 function it will grab the same record over and over. This is an issue because only one person should work on the record at one time. So sometimes it becomes possible for more than one person to select the same record, though I tried to prevent that. I have a yes/no field which is set to yes when someone opens the record, and then the query should ignore that record. But so many people are using it, it is still happening.
Any ideas would be appreciated. Thanks!
I have this so far, and it works, but it is slow.
SELECT TOP 1 tblMain.Field1, tblMain.Field2, Rnd(tblMain.Field2) As Expr1, ... FROM tblMain WHERE tblMain.COMPLETED=False ORDER BY Rnd(tblMain.Field2) DESC;
This does a great job actually finding a random record.
The problem is that it is slow. I have about 77,000 records currently. I will need to add I would say at least another 250,000 records to this database. So the speed will be very slow.
Is there a way to just get a quick query of say 100 records, then run the randomize query on just those records in order to choose one?
Or could I use an autonumber field set to random and have it somehow grab one of those?
My issue is that a form I have for working on these grabs one, but if I just use the TOP 1 function it will grab the same record over and over. This is an issue because only one person should work on the record at one time. So sometimes it becomes possible for more than one person to select the same record, though I tried to prevent that. I have a yes/no field which is set to yes when someone opens the record, and then the query should ignore that record. But so many people are using it, it is still happening.
Any ideas would be appreciated. Thanks!