mysql - how can I update a table but needing to get the update value from another select of the same table and other one? -
i have problem:
i have tablea , tableb
tableb needs tablea's id in field.
tableb , tablea have common field 'email'
ive tried this
update tableb set tableb.reference = (select a.id tablea a, tableb b a.email = b.email)
unfortunately when run query says cant specify target 'tableb' updates in clause.
any idea how solve or run query this?
update tablea, tableb set tableb.id = tablea.id tablea.email = tableb.email
or one:
update tableb inner join tablea using (email) set tableb.id = tablea.id
your query possible, need fix it:
update tableb set tableb.id = (select a.id tablea a, tableb b a.email = b.email)
Comments
Post a Comment