Hopefully someone could translate into MySQL...
Declare @ID int Set @ID = null
While Not Exists (Select * From info_grid Where ID = @ID)
Select @ID = floor( rand() * (max(id)-min(id)) ) + min(id) From info_grid
Update info_grid Set setting = @data Where ID = @ID
In other words, grab a random integer between the smallest and largest ID. If that ID doesn't exist, grab another one until you find one that does. Then update. This should work fairly quickly if there aren't major holes in your IDs (otherwise it may take the loop longer to find a random number that does exist).
This of course assumes your ID field is an integer. If you're using GUIDs, it won't help you... |