Article Directory
Problem scenario
mysql executes the followingSQL
update test set i_status=5 where s_id in (
select max(s_id) as id from test where s_title is not null
group by s_title,length(s_content) having count(*)>1
)
Execution error, suggesting Error Code: 1093. You can't specify target table 'car' for update in FROM clause
that: . This blog post mainly proposes solutions for this situation.
Problem environment
software | version |
---|---|
mysql | 5.7.27 |
problem causes
This problem will occur if the table of the subquery operation and the update operation are the same table . However, if it is just a query operation, no error will be reported and it will be executed normally. If the following SQL
is not an error, it can be executed normally.
select * from test where s_id in (
select max(s_id) as id from test where s_title is not null
group by s_title,length(s_content) having count(*)>1
)
solution
This problem can be solved by treating the subquery as a subtable and isolating it. The updated version is SQL
as follows:
update test set i_status=5 where s_id in (
select id from (
select max(s_id) as id from test where s_title is not null
group by s_title,length(s_content) having count(*)>1
) as temp
)
to sum up
The problem was solved smoothly! ! !
Ask for praise
If my article is helpful to everyone, you can click like or favorite at the bottom of the article;
if there is a good discussion, you can leave a message;
if you want to continue to view my future articles, you can click Follow
You can scan the following QR code to follow me 'S public account: Fengye Zhixuege, check out my latest share!