database - mySQL Merge Part of Table with New Table Based on Column Name, Default Value Otherwise -
database - mySQL Merge Part of Table with New Table Based on Column Name, Default Value Otherwise -
i've read ton of questions can't figure out exact solution this.
i have 2 tables different structures, below:
insert `forums` (`id`, `topics`, `posts`, `last_post`, `last_poster_id`, `last_poster_name`, `name`, `description`, `position`, `use_ibc`, `use_html`, `status`, `start_perms`, `reply_perms`, `read_perms`, `password`, `category`, `last_title`, `last_id`, `sort_key`, `sort_order`, `prune`, `show_rules`, `upload_perms`, `preview_posts`, `allow_poll`, `allow_pollbump`, `inc_postcount`, `skin_id`, `parent_id`, `subwrap`, `sub_can_post`, `quick_reply`, `redirect_url`, `redirect_on`, `redirect_hits`, `redirect_loc`, `rules_title`, `rules_text`, `has_mod_posts`, `topic_mm_id`, `notify_modq_emails`) values insert `forums` (`id`, `topics`, `posts`, `last_post`, `last_poster_id`, `last_poster_name`, `name`, `description`, `position`, `use_ibc`, `use_html`, `password`, `password_override`, `last_title`, `last_id`, `sort_key`, `sort_order`, `prune`, `topicfilter`, `show_rules`, `preview_posts`, `allow_poll`, `allow_pollbump`, `inc_postcount`, `skin_id`, `parent_id`, `redirect_url`, `redirect_on`, `redirect_hits`, `rules_title`, `rules_text`, `notify_modq_emails`, `sub_can_post`, `permission_custom_error`, `permission_showtopic`, `queued_topics`, `queued_posts`, `forum_allow_rating`, `forum_last_deletion`, `newest_title`, `newest_id`, `min_posts_post`, `min_posts_view`, `can_view_others`, `hide_last_info`, `name_seo`, `seo_last_title`, `seo_last_name`, `last_x_topic_ids`, `forums_bitoptions`, `disable_sharelinks`, `deleted_posts`, `deleted_topics`, `tag_predefined`, `archived_topics`, `archived_posts`, `ipseo_priority`, `viglink`) values
as can see, these big tables , not want solution have manually map 1 column another.
instead, want table c = table b + table a, makes new rows , inserts columns exist in table b (i.e. have have same column name). if value doesn't exist in table a, uses default or null value.
so clarify, "id
, topics
, posts
, last_post
," nowadays in both, when merged there should new rows info these filled out. however, 'password' column in different location in each table; despite this, should fill out table b's "password" value table a's. columns exist in table b, should take default or null value such 'permission_custom_error', , columns in table not table b, should ignored (the info columns not transfer over).
i not want manually map columns, nor can manually restructure info there way many rows (especially in other tables have merge).
i couldn't find question quite why had inquire it. sorry if it's poor question... , regardless, have great day.
mysql database table merge
Comments
Post a Comment