php - query to update record with another random record from another table? -



php - query to update record with another random record from another table? -

im having problem little issue within query

$update = mysql_query("update earnings set userid = (select id users installid not null order rand() limit 1) userid='0'");

this query update userid within earning table when value of '0' need update userid not found within user table illustration earnings table has 5 entries userid=10 userid 10 not found in users table , users table have ids (1'2'3'4'5) update userid have value 10 of ids found within users table , have installid not nulled

i'd imagine client want earnings data, of things, relevant, not completely random (if if info random , don't know which, of info corrupted). said, query gets want with

update earnings set userid = (select id users installid not null order rand() limit 1) userid not in (select id users)

what i'd instead set foreign key on id , prevent random info beingness written in in first place. cannot see solution having random ids improve not having rows @ all. if ids not important, why have them @ all?

php mysql

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -