A
A
Alexander2017-02-07 15:53:28
MySQL
Alexander, 2017-02-07 15:53:28

How to duplicate a parent-child relationship with update?

The table has an id and parent_id field, this is a parent-child relationship, it is not filled in, more precisely, only id is filled. And there is a link code and parent_code, it is filled. Question - how do I duplicate the code-parent_code relationship for the id-parent_id fields

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2017-02-07
@Captain

UPDATE `table` AS `t1`
  JOIN `table` AS `t2` ON `t2`.`code` = `t1`.`parent_code`
  SET `t1`.`parent_id` = `t2`.`id`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question