开发者

update mysql table with random value from another query?

im having a problem regrading a query which will update earning table with another random value from users table. when executing the query it do nothing

$update = mysql_query("UPDATE earnings SET userid = (SELECT ID FROM users WHERE installid is NULL ORDER BY rand开发者_开发知识库()) WHERE userid='0'");

in the second query

SELECT ID FROM users WHERE installid is NULL ORDER BY rand()

it will get me a random userid where installid null


Have you tried that query in phpMyAdmin etc? Are you getting an error?

Have you tried:

SELECT ID FROM users WHERE installid is NULL ORDER BY rand() LIMIT 1

So that the full query becomes:

UPDATE earnings SET userid = (SELECT ID FROM users WHERE installid is NULL ORDER BY rand() LIMIT 1) WHERE userid='0'

However keep in mind that you may end up having duplicate userid values in the earnings table.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜