Created
September 1, 2014 07:10
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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