繁体   English   中英

插入加入限制 - Mysql

[英]Insert Join with limit - Mysql

如何在使用限制时使用连接进行更新

错误 - 非法使用限制运算符

UPDATE  
     table1  
INNER JOIN table2 ON table1.id = table2.id  
SET  
     table1.field = 'your_value'
WHERE  
     table1.id = table2.id  
LIMIT 1500

可能的解决方案,这是一个黑客攻击

SET @tmp_c = 0;
UPDATE
    table1
INNER JOIN table2 ON table1.id = table2.id
INNER JOIN table3 ON table2.id = table3.id
SET
    table1.remove_date = NOW() - INTERVAL 5 MONTH
WHERE
    table1.active = 1
AND
    (IF (table1.active = 1, @tmp_c := @tmp_c + 1 , 0 )) //This is to only increment the counter if the whole where matches
AND
    @tmp_c <= 15 //Start ignoring row items as soon as it exceeds the limit amount 

;

如果你想要限制,你应该使用一个子选择并加入它

UPDATE  table1  
INNER JOIN ( select * from table1 
INNER JOIN table2 ON table1.id = table2.id  
LIMIT 1500 ) t on t.id = table1.id
SET  table1.field = 'your_value'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM