56,679
社区成员
发帖
与我相关
我的任务
分享
begin transaction
select * from table where state=0 limit 1, 50
update table set state=1, getuser=5 where id in (上面50条记录的id号)
comit transaction
begin transaction
update table set state=1, getuser=5 where state=0 limit 1, 50
commit transaction
BEGIN trans
SELECT * FROM table WHERE state=0 LIMIT 3 (这里取出的id=1,2,3)
UPDATE table SET state = 1,getuser='aaa111' WHERE id IN (1,2,3) AND state=0
COMMIT trans
主要是想实现,用户取到50条,就只更新这50条记录,并且这个用户在客户端看到的也是这50条记录。
另一个用户B,也是这样,如果直接update table set state=1 where state=0 limit 50的话,那这个用户B 查询出来的是1-50条,看到的也是1-50条,但更新的即是50-100条了。