0

I have the following MySQL query which performs a simple update. There's a sub query after the and clause which works as a separate query, the main query also works on it's own i.e without the sub query (with some valid numeric value in place). I get the following error however:

Error Code: 1093. You can't specify target table 'postmeta' for update in FROM clause

The query is here:

UPDATE postmeta
SET meta_value = 'visible'
WHERE meta_key = '_visibility'
AND post_id = ( SELECT post_id
FROM postmeta
WHERE meta_key = '_sku'
AND meta_value = 846635025502
LIMIT 1 )

Can anyone suggest what the issue is here. Thanks

bfontaine
  • 18,169
  • 13
  • 73
  • 107
Liam Fell
  • 1,308
  • 3
  • 21
  • 39
  • This is not allowed . Explanation here : [You can't specify target table for update in FROM clause](http://stackoverflow.com/questions/4429319/you-cant-specify-target-table-for-update-in-from-clause) – Developer Jan 04 '16 at 10:47

1 Answers1

0

In MySQL, you can't modify the same table which you use in the SELECT part. This behaviour is documented at: http://dev.mysql.com/doc/refman/5.6/en/update.html

Please check the link.