Arjuna Aircraft Ident.: F-MBSD | Salut,
Je voudrais faire un "update multitable" avec MySQL.
D'après la doc, on peut :
Citation :
Starting with MySQL 4.0.4, you can also perform UPDATE operations that cover multiple tables. The table_references part lists the tables involved in the join. Its syntax is described in Section 13.2.7.1, JOIN Syntax. Here is an example:
Code :
- UPDATE items,month SET items.price=month.price
- WHERE items.id=month.id;
|
|
Pourtant, lorsque je fais ma requête, il râle :
Code :
- update terrain t1, (select distinct idsolarsystem from terrain) solarsystem, (select distinct idsolarsystem, idplanet from terrain) planet
- set t1.owner = 1
- where (planet.idplanet = t1.idplanet and planet.idsolarsystem = t1.idsolarsystem)
- and (solarsystem.idsolarsystem = planet.idsolarsystem)
- and (select count(*) from terrain t2 where t2.idsolarsystem = t1.idsolarsystem
- and t2.idplanet = t1.idplanet and t2.owner is null and t2.xterrain between t1.xterrain - 2
- and t1.xterrain + 2 and t2.yterrain between t1.yterrain - 2 and t1.yterrain + 2) = 25
|
Code :
- ERROR 1093 (HY000): You can't specify target table 'terrain' for update in FROM clause
|
PS: à la base, j'avais viré l'alias "T1", mais ça ne change rien.
PS²: Pourtant, c'est pas la présence de Terrain plusieur fois qui le gêne, cette requête bidon fonctionne :
Code :
- update terrain T1, terrain T2 set T1.owner = 1 where T1.xterrain = T2.xterrain and T1.yterrain = T2.yterrain and T2.idplanet = 1;
|
|