Q
Q
QNA-19762020-02-07 11:01:20
MySQL
QNA-1976, 2020-02-07 11:01:20

Why update join swears at limit, select join doesn't?

I noticed that when select with join tables by limit, everything works, but in update with join tables by limit, the error is: SQLSTATE[HY000]: General error: 1221 Incorrect usage of UPDATE and LIMIT

Someone can explain why, because when updating one tables on limit everything works.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
netyshka, 2020-02-07
@QNA-1976

"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." - This is exactly the answer to your question.
If you need to make a limit nosebleed, then the query should look something like this:
UPDATE table1 t JOIN
(
SELECT p.value1, p.value2
FROM table1 p JOIN table2 m
ON p.id= m.id
ORDER BY p.id
LIMIT 100
) s
ON t.id = s.id
SET t.value = s.value;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question