There is a table A(id, b_id, value) in which the b_id column refers to the id column of table B(id, value) . Previously, value was stored in table A , but now table B added (it is still empty) where you need to insert records and transfer data. I mean that I will do something like insert into B (value) select value from A and thus for each record from table A will create an entry in table B , but I don’t know how to record A.b_id link to the created record . Unless to fulfill request from somewhere from php for example and insert line by line into table B and update table A Is it possible to do this from mysql somehow?

  • one
    If value is unique, then after insert you can find all the records and put down the corresponding id. If not, it depends on the completeness of the data transfer. if, say, all values ​​are transferred one-to-one, then you can first fill b_id with serial numbers in A, then rewrite all the values ​​with ready id in B and set the autoincrement (if any) on table B to the next value after the maximum inserted id - Mike
  • @Mike value is not unique and all entries are transferred. And how from mysql to fill b_id with sequence numbers? I tried like this, but it did not work: set @index = 0; update A set @index = @index + 1 set b_id = @index; set @index = 0; update A set @index = @index + 1 set b_id = @index; - PECHAPTER
  • @Mike, everything turned out: set @index = 0; update A set b_id = (@index := @index + 1); set @index = 0; update A set b_id = (@index := @index + 1); . Thank! - PECHAPTER

0