Is there a way to update random records?

I have a database of 5.6 million records and I want to pull out 5000
records and mark a field in the database that I've pulled these so that I
don't pull the same 5000 again.

I know I can select the records by doing:

SELECT * FROM 5600k WHERE picked IS NULL ORDER BY rand() LIMIT 5000;

But what I really want to do is:

UPDATE 5600k SET picked=1 WHERE picked IS NULL ORDER BY rand() LIMIT 5000;

Then doing:

SELECT * FROM 5600k WHERE picked=1;

Then resetting the table so I can pick a random selection again later:

UPDATE 5600k SET picked=0 WHERE picked=1;

So can the update statement be done to update random records?


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to