create table apples(variety char(10) primary key, price int); insert into apples values('fuji', 5), ('gala', 6); update apples set price = (select price from apples where variety = 'gala') where variety = 'fuji';
错误提示是:ERROR 1093 (HY000): You can't specify target table 'apples' for update in FROM clause. MySQL手册这下面有说明 : “Currently, you cannot update a table and select from the same table in a subquery.” 在这个例子中,要解决问题也十分简单,但有时候不得不通过查询子句来update目标。好在我们有办法。