Achilles Achilles - 5 months ago 35
MySQL Question

Error Code: 1093. Table 'site_html' is specified twice, both as a target for 'UPDATE' and as a separate source for data

I want to update the 'status' column of the table with respective id , but it leads me to error code 1093.
Below is my SQL Query

Update site_html Set status='Update Found'
Where id = (
select id
from site_html
where link='http://www.example.com');


How can i correct this error? I am new to SQL .

Answer

In MySQL, you can't modify the same table name directly which you use in the SELECT part. So you can do it through table alias.

update site_html AS s, (select id  from site_html where link='http://www.example.com') AS t
set status='Update Found' 
where s.id = t.id;
Comments