sábado, 17 de setembro de 2011

[DBA] - mysql update with self values

interesting how a simple:

update tab1 set field1=(select field1 from tab1 where field1=field2)

cannot be simply done in mysql. you need some workarounds like another duplicate table or as demonstrated at
http://www.xaprb.com/blog/2006/06/23/how-to-select-from-an-update-target-in-mysql/
since mysql "materializes subqueries in the FROM clause (“derived tables”) as temporary tables, wrapping the subquery into another inner subquery in the FROM clause causes it to be executed and stored into a temporary table, then referenced implicitly in the outer subquery.  "

The error message is:
ERROR 1093 (HY000): You can't specify target table '<whatever>' for update in FROM clause."

Strange.

Sem comentários:

Enviar um comentário