sql - Union of two tables with the same columns and same where clause -
i have 2 sql tables in 2 different locations contain exact same fields, different data (all unique skus). i'd join tables , run complex clause on result logging purposes.
what have in place works, appears massively redundant (i'm coming c# background here).
select sku, catalogname, getdate() uswebdb.commerce.catalogproducts sku not null , (categoryname not null or parentoid = 113) , (sku not '%[a-z]%') union select sku, catalogname, getdate() ukwebdb.commerce.catalogproducts sku not null , (categoryname not null or parentoid = 113) , (sku not '%[a-z]%')
is there more concise way join these 2 tables , produce similar result, or best approach? selected fields same, number of tables involved , complexity of clause might increase in near future.
i guess ideally i'd see this:
select sku, catalogname, getdate() uswebdb.commerce.catalogproducts --magic join/union-- ukwebdb.commerce.catalogproducts -- more joins...-- sku not null , (categoryname not null or parentoid = 113) , (sku not '%[a-z]%')
is possible in sql2008? over-thinking this?
are these on different servers or different databases, because makes big difference. syntax implies on same server, different database, means can move where
outside:
select sku, catalogname, getdate() ( select sku, catalogname, categoryname, parentoid uswebdb.commerce.catalogproducts union select sku, catalogname, categoryname, parentoid ukwebdb.commerce.catalogproducts ) f (f.categoryname not null or f.parentoid = 113) , (f.sku not '%[a-z]%')
you shold use ctrl-l see if query plan different. there might performance repercussions.
Comments
Post a Comment