sql - How to update column in mysql by joining from another tables? -
i had database, rebuilt optimization.
here :
users
(p) user_id pseudo images
(p) image_id path tags
(p) tag_id #image_id #user_id (int) tag the older table tags :
old_tags
(p) tag_id #image_id author (varchar) tag my problem : old_tags full of datas (around 6000 rows) , tags empty, want convert data old_tags new tags table format. column different, author varchar , user_id int. there link between old_tags , users because author refers pseudo.
i want like:
update tags set user_id = (select user_id users, old_tags users.pseudo = old_tags.author) i don't know if it's clear, want same in new tags table instead of 'author' want corresponding 'user_id'. working phpmyadmin, if possible suggest can run directly in it. thx in advance!
you have insert add new rows table:
insert tags (tag_id, image_id, user_id, tag) select ot.tag_id, ot.image_id, u.user_id, ot.tag old_tags ot join users u on ot.author = u.pseudo
Comments
Post a Comment