MySql How to search in comparison with the replacement?

Good
There is the task of handling thousands of records.
The bottom line: you Need to replace in the field parent value name ID
insert ID instead of the name in the parent, if the parent name matches the ID Name
Example table:
(Vasya replaced by 1, Vassiliy replace with 11)

ID | Name | Parent
(1, Vasya, Petya),
(2, Misha, Vasya),
(3, Grisha, Vasya),
(4, Pasha, Vasya),
(5, Masha, Vasya),
(6, Serj, Vassiliy),
(7, Ivan1, Vassiliy),
(8, Ivan2, Vassiliy),
(9, Garik, Vassiliy),
(10, Vassiliy, Vassiliy),
(11, Vassiliy, Petrovich),
June 5th 19 at 21:06
2 answers
June 5th 19 at 21:08
Solution
Get used to it, if you have a one-time task - to carry its ax. Here is the truth. Sense to come up with a beautiful script, if you can take and too much to sort through. And figure that the script will run 10 minutes (although the actual per minute can handle it.)

In any case we suggest to add a field parent_id and not to record the figures in parent and manipulate this field. It is not always the solution may be to be elegant.

Algorithm 1)
To pull out one ID (1 if permanent list) and run the query to update:
"update users set parent_id=3 where Parent=Grisha"

Algorithm 2)
Add is_read field temporarily, where the default is set to 0
You can temporarily add a tag reader, then the query will be faster
and just iterate.

Algorithm 3)
If you are already well versed in mysql queries:
UPDATE users i INNER JOIN
users o
ON i.name = o.parent
SET o.parent_id = i.id
Thanks for the tip.
Something that is necessary.
Option 1 use if there is a slight difference and not a lot of variations. - nikita.Stracke commented on June 5th 19 at 21:11
June 5th 19 at 21:10
simple update + join on the same table
for you request to write chtoli? this is the basics

Find more questions by tags MySQL