如何在使用限制时使用联接进行更新
错误 - 非法使用限制运算符
UPDATE
table1
INNER JOIN table2 ON table1.id = table2.id
SET
table1.field = 'your_value'
WHERE
table1.id = table2.id
LIMIT 1500
答案 0 :(得分:2)
可能的解决方案,它有点像黑客
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
答案 1 :(得分:1)
如果您想要限制,则应使用子选择并加入此
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'