Click here to Skip to main content
15,916,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have two tables:

Table 1

skuproduct_namecolor
1aproduct1black
1bproduct2red


Table 2

skuproduct_namedimensions
2aproduct310x10x30
2bproduct420x25x50


These tables belong to different product category types. sku is a primary key for each table. I need a master table that contains all products from every category type. The master table that I need is like:

Master Table

skuproduct_namecolordimensions
1aproduct1black
1bproduct2red
2aproduct310x10x30
2bproduct420x25x50


How can I join Table1 and Table2 to get Master Table?

Thank you.
Posted

1 solution

Use a union query.

eg:

SQL
select sku, product_name, color, '' as dimensions from [table 1]
union all
select sku, product_name, '' as color, dimensions from [table 2]
 
Share this answer
 
Comments
Soner Aydemir 6-Dec-11 20:26pm    
Thanks for the answer. I've about 10 tables, each table has about 100 columns and each table has some common columns. Is there any solution to merge them automatically or do I need to enter all the columns one by one like your example?
_Damian S_ 6-Dec-11 20:36pm    
Sadly, you will need to do it like my example if you are wanting it to turn out like your question above... It's important to use the same number of fields in the same order for each table!!
Soner Aydemir 6-Dec-11 21:30pm    
Thank you very much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900