-2

I use the following query:

update city 
set CountryCode = (select CountryCode from city where id = 1)       
where id =4081;

and I am getting the below error:

Error Code: 1093. You can't specify target table 'city' for update in FROM clause

but I am not sure why this is not allowing me to do so?

john
  • 613
  • 1
  • 7
  • 25
Aakash Goyal
  • 305
  • 1
  • 4
  • 22
  • 1
    -1 for spending 0 time googling for solution. – N.B. Aug 28 '14 at 13:36
  • 1
    possible duplicate of [Mysql error 1093 - Can't specify target table for update in FROM clause](http://stackoverflow.com/questions/45494/mysql-error-1093-cant-specify-target-table-for-update-in-from-clause) – N.B. Aug 28 '14 at 13:37

1 Answers1

1

A little trick you can use is this that makes use of a sub subquery:

UPDATE
  city
SET
  CountryCode = (SELECT * FROM (SELECT CountryCode FROM city where ID=1) s)
WHERE
  id=4081;
fthiella
  • 48,073
  • 15
  • 90
  • 106