MySQL: How to copy column from one table without id into another table? -


is possible copy column 'hash' table2 column 'hash' in table1 ?

thank help! kind regards, paul

table 1 +----+--------+----------+ | id | name   | hash     | +----+--------+----------+ | 21 | john   |          | | 22 | ann    |          | | 23 | peter  |          | +----+--------+----------+  table 2 +----------+ | hash     | +----------+ | vfrtycfg | | gtytghjg | +----------+ 

i need result:

+----+--------+----------+ | id | name   | hash     | +----+--------+----------+ | 21 | john   | vfrtycfg | | 22 | ann    | gtytghjg | | 23 | peter  |          | +----+--------+----------+ 

update table1 t1 join (select @rownum rownum, hash, @rownum := @rownum + 1       table2       cross join (select @rownum := min(id) table1) var) t2 on t1.id = t2.rownum set t1.hash = t2.hash 

demo

the subquery adds rownum column table2, containing sequential ids starting minimum id in table1.


Comments