I wanted to update MySQL table with certain rules. I have let's say 3 column: ID, Name, Checked
and I want to update Name
to all rows equally where Checked = 0
. In another table I have list 'Names` from where I pull my names.
Is this possible to do with one UPDATE
query, or do i need to use some loop? Will there be a problem if let's say I have 11 rows to update but i have 10 names, how the query update those fields.
I find solution:
UPDATE `table` SET `ID` = (select `ID` from `name` ORDER BY rand() LIMIT 1) WHERE `Lock_ID` = 0
This query will randomly use name from other table and update it (it is 99% correct solution) it will redistribute name's almost the same for every row.