2

I wrote this delete for an application with mysql db and it doesn't work, I already search for answers but I cant find any kind error, someone can help me with a tip about this? thanks

1093 - You can't specify target table 'md1_acessos' for update in FROM clause

DELETE FROM md1_acessos
WHERE ID_USUARIO = 10
AND ID_UNIDADE not in ( 
    SELECT ID_UNIDADE 
    FROM md1_acessos
    WHERE ID_EMPRESA = 1
    AND ID_USUARIO = 1
    AND ID_MODULO IN (1,2,6)
);
Taryn
  • 242,637
  • 56
  • 362
  • 405
Matheus Hernandes
  • 629
  • 1
  • 6
  • 25
  • 1
    See this for a workaround. http://verysimple.com/2011/03/30/mysql-cant-specify-target-table-for-update-in-from-clause/ – John Powell Jun 10 '14 at 12:32
  • Or http://stackoverflow.com/questions/9285143/mysql-you-cant-specify-target-table-a-for-update-in-from-clause – John Powell Jun 10 '14 at 12:33

1 Answers1

0

Try this:

DELETE FROM md1_acessos
WHERE ID_USUARIO = 10
AND NOT 
    (ID_EMPRESA = 1
    AND ID_USUARIO = 1
    AND ID_MODULO IN (1,2,6))
Joe Taras
  • 15,166
  • 7
  • 42
  • 55