2015-07-21 50 views
0
update accounts a 
left join users b on 
    a.user_id = b.user_id 
set `sold` = '1' where b.country = 'UA' AND a.site = 'od' 

如何限制此查询?限额更新声明

试图

update accounts a 
left join users b on 
    a.user_id = b.user_id 
set `sold` = '1' where b.country = 'UA' AND a.site = 'od' LIMIT 500 

,但得到错误错误:UPDATE并限制使用不当

+5

你不能限制的更新,你* can * do是限制'select'并更新该选择的结果。这将需要一个存储过程或函数AFAIK(但我不是DBA ...)。 – alfasin

回答

0

试试这个

update accounts a left join users b on a.user_id = b.user_id 
set 'sold' = '1' 
where b.country in 
(select country from 
(select country from users where 
country = 'UA' order by user_id asc limit 500) tmp) and 
a.site in 
(select site from 
(select site from accounts where 
site = 'od' order by user_id asc limit 500) tmp2); 

有关SELECT语句的限制进一步详情请参阅本。

http://www.techonthenet.com/sql/select_limit.php

0

我会先用热膨胀系数表(临时表)来保存你的极限查询,然后使用该表进行更新:

With LimitQuery As 
(
select * from accounts a 
left join users b on 
    a.user_id = b.user_id 
where b.country = 'UA' AND a.site = 'od' LIMIT 500 
) 

update LimitQuery 
set `sold` = '1'