Advance Query with Join

Posted by user1462589 on Stack Overflow See other posts from Stack Overflow or by user1462589
Published on 2012-06-18T02:51:10Z Indexed on 2012/06/18 3:16 UTC
Read the original article Hit count: 127

Filed under:
|
|
|
|

I'm trying to convert a product table that contains all the detail of the product into separate tables in SQL. I've got everything done except for duplicated descriptor details.

The problem I am having all the products have size/color/style/other that many other products contain. I want to only have one size or color descriptor for all the items and reuse the "ID" for all the product which I believe is a Parent key to the Product ID which is a ...Foreign Key. The only problem is that every descriptor would have multiple Foreign Keys assigned to it. So I was thinking on the fly just have it skip figuring out a Foreign Parent key for each descriptor and just check to see if that descriptor exist and if it does use its Key for the descriptor.

Data Table

PI  Colo   Sz   OTHER


1        |   Blue  |  5  |    Vintage

2        |   Blue  |  6   |   Vintage

3        |   Blac  | 5   |   Simple

4        |   Blac |  6   |   Simple

===================================

Its destination table is this

===================================

DI Description

1       |   Blue

2       |   Blac

3       |   5

4       |   6

6       |   Vintage

7       |  Simple 

=============================

Select Data.Table

Unique.Data.Table.Colo

Unique.Data.Table.Sz

Unique.Data.Table.Other

=======================================

Then the dual part of the questions after we create all the descriptors how to do a new query and assign the product ID to the descriptors.

PI| DI

1 | 1

1 | 3

1 | 4

2 | 1

2 | 3

2 | 4

By figuring out how to do this I should be able to duplicate this pattern for all 300 + columns in the product. Some of these fields are 60+ characters large so its going to save a ton of space.

Do I use a Array?

© Stack Overflow or respective owner

Related posts about sql

Related posts about arrays