Jump to content

Update statement, how would I select and change 100 random from selection


TecTao

Recommended Posts

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.

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)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.