1
update email_template_mapping
    set template_footer = (select id
                           from email_template_mapping
                           where template_description = 'footer'
                          );

this query giving me error You can't specify target table 'email_template_mapping' for update in FROM clause.

can you please help. Thanks in advance.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
swayam swayam
  • 131
  • 1
  • 12
  • Possible duplicate of [MySQL Error 1093 - Can't specify target table for update in FROM clause](https://stackoverflow.com/questions/45494/mysql-error-1093-cant-specify-target-table-for-update-in-from-clause) – Ricardo Pontual Jun 19 '18 at 11:41

2 Answers2

2

In MySQL, you need to express this using JOIN:

update email_template_mapping etm left join
       email_template_mapping etmf
       on etmf.template_description = 'footer'
    set etm.template_footer = etmf.id;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
1
update email_template_mapping
set template_footer =  id
where template_description = 'footer'

should look something like this, it looks like in that subquery youre using the same table so you can just set the template footer = id and then use the where after. Look up the format for an update statement and that will point you in the correct direction too, hope that helps! :)

t..
  • 1,101
  • 1
  • 9
  • 22