我需要一种通过rand()选择行的方法,并在MYSQL上的同一查询中更新它
我试过这段代码但没有回答:
SET AUTOCOMMIT=0;
BEGIN TRANSACTION;
select * from articles where status = 3 and name IS NOT NULL ORDER BY RAND() limit 0,1;
update articles set status = 4 ;
COMMIT TRANSACTION;
答案 0 :(得分:0)
这为我工作:
update articles set `status` = 4 where id in (
SELECT id FROM (
select id from articles where status = 3 and name IS NOT NULL ORDER BY RAND() limit 0,1
) tmp
);