TecTao Posted December 14, 2011 Share Posted December 14, 2011 There are about 400 records in a database with a field zabp_package = T_SIMT. They were uploaded in an order where specific category lists were uploaded together. For example, first 100 dining, then 75 insurance, then 150 health, then 75 cars. So from an auto increment standpoint they were inserted in that order. I want to select at random 100 of these 400 and update two fields. My update statement is: update `usersOld` SET `m_org` = 'ZABP.org Corporate HQ' , `m_orgID` = 'PFL2a96bW' WHERE `zabp_package` = 'T_SIMT' This works for all, I just need to limit a random selection to 100. Any Help on this, thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/253182-update-statement-how-would-i-select-and-change-100-random-from-selection/ Share on other sites More sharing options...
requinix Posted December 14, 2011 Share Posted December 14, 2011 I have yet to come up with a good reason why you'd want to do this, but whatever. Use an IN and a subquery: ...WHERE ID IN (SELECT ID FROM usersOld ORDER BY RAND() LIMIT 100) Quote Link to comment https://forums.phpfreaks.com/topic/253182-update-statement-how-would-i-select-and-change-100-random-from-selection/#findComment-1297974 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.