Skip to content

Instantly share code, notes, and snippets.

@meeuw
Created September 1, 2014 07:10
Show Gist options
  • Save meeuw/e53d9fb2aabbf700eb11 to your computer and use it in GitHub Desktop.
Save meeuw/e53d9fb2aabbf700eb11 to your computer and use it in GitHub Desktop.
merge multiple tables (same tables from different databases) into one table (@from is import table name, @contents is column, @TagName is key, @site is column)
insert into pivot
select distinct NULL, `@from`.`@tagname`, '@from-@contents', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL from `@from`
left join pivot on `pivot`.`tagname` = `@from`.`@tagname` and '@from-@contents' = `pivot`.`category`
where `pivot`.`tagname` is null;
update `pivot`
inner join `@from` on `pivot`.`tagname` = `@from`.`@tagname` and '@from-@contents' = `pivot`.`category`
set `pivot`.`@site` = `@contents`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment