MySQL database update subquery
For example:
UPDATE test. tb_vobile aset a. name = '000000' WHEREa. id = (select max (id) id from test. tb_vobile)
Error:
[SQL] UPDATE test. tb_vobile aset. name = '000000' WHEREa. id = (select max (id) id from test. tb_vobile) [Err] 1093-You can't specify target table 'A' for update in FROM clause
You can:
UPDATE test. tb_vobile ajoin (select max (id) id from test. tb_vobile) bon. id = B. idset. name = '20140901'; or UPDATE test. tb_vobile a, (select max (id) id from test. tb_vobile) bset. name = '000000' WHEREa. id = B. id;
Note:
1. During update, the updated table cannot be used in set and where for subqueries;
2. During update, you can update multiple tables (not SQL Server );
For example, update ta a, tb B set a. Bid = B. id, B. Aid = a. id;
3. Any query can be performed after update, which is equivalent to from;