网络营销电子商务研究中心

网络营销电子商务研究中心 (https://www.0058.net/index.php)
-   MySQL (https://www.0058.net/forumdisplay.php?f=76)
-   -   Flag large number random records in a MySQL database - one time only (https://www.0058.net/showthread.php?t=5097)

Galax city 2015-04-19 08:18 AM

Flag large number random records in a MySQL database - one time only
 
In my database table I've got 5 columns, id, l_num, s_num, win, claimed. There are 415,000 records. How would I randomly select 20,000 of those records and update the record with a 1 in the win field?

I understand that I could use SELECT * FROM tableName ORDER BY RAND() LIMIT 20000 to select those random records, but I've also read that this type of select would be inefficient for a large number.

I only need to perform this once on the database. Once all the records are flagged, we're simply checking against that flag one at a time.

Gann Valley 2015-04-19 08:19 AM

You can use the following query:
Code:

UPDATE tableName SET win = 1 ORDER BY RAND() LIMIT 20000


All times are GMT +8. The time now is 12:16 AM.

Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.