Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

SQL:UPDATE com INNER JOIN com LIMIT


Você simplesmente não pode.

De acordo com documentos MySQL para UPDATE :
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. 

ATUALIZAÇÃO 1
UPDATE  table1 a
        INNER JOIN
        (
            SELECT  id 
            FROM    table1 A
                    INNER JOIN table2 B 
                        ON A.type = B.typeName
            WHERE   A.status IN ('Finished', 'Exception', 'Query') AND 
                    A.date BETWEEN '2013-01-01' AND '2013-01-31' AND 
                    A.code IN ('ex1','ex2','ex3') AND 
                    A.closed = 0 AND 
                    B.order = 'Non-Order' AND 
                    A.userName = 'test' 
            LIMIT   3
        ) tmp ON a.ID = tmp.ID
SET     a.closed = 1, 
        a.sample = 1