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目標。好在我們有辦法。