且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用ORDER BY和LIMIT进行的更新在MYSQL中不起作用

更新时间:2022-12-18 09:07:16

通常,您可以在UPDATE语句中使用LIMITORDER,但对于您而言,则不能如

Usually you can use LIMIT and ORDER in your UPDATE statements, but in your case not, as written in the MySQL Documentation 12.2.10. UPDATE Syntax:

对于多表语法,UPDATE会更新每个名为的表中的行 在满足条件的table_references中.在这种情况下,订购 不能使用BY和LIMIT.

For the multiple-table syntax, UPDATE updates rows in each table named in table_references that satisfy the conditions. In this case, ORDER BY and LIMIT cannot be used.

请尝试以下操作:

UPDATE Ratemaster
SET Ratemaster.Rate =
(
    SELECT Rates.Rate
    FROM Rates
    WHERE Ratemaster.user = Rates.user
    ORDER BY Rates.id
    LIMIT 1
)