dylanpedro
New member
- Local time
- Today, 00:36
- Joined
- Jan 28, 2015
- Messages
- 8
Hi,
I am in the process of designing a database but require some help with how the tables should be setup and if queries can return the required information.
This is the basic information of what is required:
The company has many products and each product can either be a single product or belong to a group of products for example all products in the group are the same but the only difference is either different colours or different sizes etc.
On top of this each product can have many different attributes assigned to them for example: finish_type, material_composition etc.
Originally each of these values was set to each product and there was a lot of duplicate values across variation products and therefore it has been advised that these attributes be applied to the group of products rather than each product but if any attribute is different for each product, then that be applied to each product e.g. size, colour etc.
Then when a query is ran it will fetch all the attributes for single product, all the attributes for all grouped products from the variation group and lastly any attributes applied separately to the variation products.
The tables originally we setup as follows:
ProductVariationGroups Table
PK_ProductVariationGroups_ID
VariationGroupName
ProductInfo Table
PK_ProductInfo_ID
FK_ProductVariationGroups_ID REFERENCES ProductVariationGroups (PK_ProductVariationGroups_ID)
Product SKU
Attributes Table (Look up table for values for Single Products or Variation Groups)
PK_Attribute_ID
AttribName
AttribValue
AttribType ?(maybe required, read about later)
ProductAttributes Table (Contains attributes mapped to Individual Products)
PK_ProductAttributes_ID
FK_ProductInfo_ID REFERENCES ProductInfo (PK_ProductInfo_ID)
FK_Attribute_ID REFERENCES Attributes (PK_Attribute_ID)
FK_AttribType REFERENCES Attributes (AttribType) ?(maybe required, read about later)
ProductVariationAttributes Table (Contains attributes mapped to VariationGroups)
FK_ProductVariation_ID REFERENCES ProductVariationGroups (PK_ProductVariationGroups_ID)
FK_Attribute_ID REFERENCES Attributes (PK_Attribute_ID)
FK_AttribType REFERENCES Attributes (AttribType) ?(maybe required, read about later)
First is it possible to have just one table that can store both attributes for individual products and variation groups instead of having two different tables (ProductAttributes/ProductVariationAttributes)
Also using the layout above I have managed to make a union query which shows all the attributes that apply to the Variation group and then any that have been applied to the products themselves e.g.
SELECT ProductInfo.SKU, Attributes.AttribName, Attributes.AttribValue
FROM ProductInfo INNER JOIN (Attributes INNER JOIN ProductAttributes ON Attributes.PK_Attribute_ID = ProductAttributes.FK_Attribute_ID) ON ProductInfo.PK_ProductInfo_ID = ProductAttributes.FK_ProductInfo_ID;
UNION
SELECT ProductInfo.SKU, Attributes.AttribName, Attributes.AttribValue
FROM (ProductVariationGroups INNER JOIN ProductInfo ON ProductVariationGroups.PK_ProductVariationGroups_ID = ProductInfo.FK_ProductVariationGroups_ID) INNER JOIN (Attributes INNER JOIN ProductVariationAttributes ON Attributes.PK_Attribute_ID = ProductVariationAttributes.FK_Attribute_ID) ON ProductVariationGroups.PK_ProductVariationGroups_ID = ProductVariationAttributes.FK_ProductVariation_ID;
The problem with the query is that if an attribute has been applied to the variation group such as AttribNameame = "Gift Wrap Available" AttribValue = "Yes" and then an attribute has been applied to the product such as AttribNameame = "Gift Wrap Available" AttribValue = "No", the query shows both attributes where as the product attribute should take precedence, and therefore the query should only show AttribNameame = "Gift Wrap Available" AttribValue = "No".
I think it has something to do with the Attributes,ProductAttributes and ProductVariationAttributes all needing a column for AttribType and that way the query can tell that both values belong to the same type and only use the value from the ProductAttributes instead of ProductVariationAttributes.
I hope this make sense and have written this in very broad terms to get the basic logic across and am willing to expand on it if necessary. Also I have included screenshots of the basic table relationships and queries used and a sample database.
Regards,
Dylan
I am in the process of designing a database but require some help with how the tables should be setup and if queries can return the required information.
This is the basic information of what is required:
The company has many products and each product can either be a single product or belong to a group of products for example all products in the group are the same but the only difference is either different colours or different sizes etc.
On top of this each product can have many different attributes assigned to them for example: finish_type, material_composition etc.
Originally each of these values was set to each product and there was a lot of duplicate values across variation products and therefore it has been advised that these attributes be applied to the group of products rather than each product but if any attribute is different for each product, then that be applied to each product e.g. size, colour etc.
Then when a query is ran it will fetch all the attributes for single product, all the attributes for all grouped products from the variation group and lastly any attributes applied separately to the variation products.
The tables originally we setup as follows:
ProductVariationGroups Table
PK_ProductVariationGroups_ID
VariationGroupName
ProductInfo Table
PK_ProductInfo_ID
FK_ProductVariationGroups_ID REFERENCES ProductVariationGroups (PK_ProductVariationGroups_ID)
Product SKU
Attributes Table (Look up table for values for Single Products or Variation Groups)
PK_Attribute_ID
AttribName
AttribValue
AttribType ?(maybe required, read about later)
ProductAttributes Table (Contains attributes mapped to Individual Products)
PK_ProductAttributes_ID
FK_ProductInfo_ID REFERENCES ProductInfo (PK_ProductInfo_ID)
FK_Attribute_ID REFERENCES Attributes (PK_Attribute_ID)
FK_AttribType REFERENCES Attributes (AttribType) ?(maybe required, read about later)
ProductVariationAttributes Table (Contains attributes mapped to VariationGroups)
FK_ProductVariation_ID REFERENCES ProductVariationGroups (PK_ProductVariationGroups_ID)
FK_Attribute_ID REFERENCES Attributes (PK_Attribute_ID)
FK_AttribType REFERENCES Attributes (AttribType) ?(maybe required, read about later)
First is it possible to have just one table that can store both attributes for individual products and variation groups instead of having two different tables (ProductAttributes/ProductVariationAttributes)
Also using the layout above I have managed to make a union query which shows all the attributes that apply to the Variation group and then any that have been applied to the products themselves e.g.
SELECT ProductInfo.SKU, Attributes.AttribName, Attributes.AttribValue
FROM ProductInfo INNER JOIN (Attributes INNER JOIN ProductAttributes ON Attributes.PK_Attribute_ID = ProductAttributes.FK_Attribute_ID) ON ProductInfo.PK_ProductInfo_ID = ProductAttributes.FK_ProductInfo_ID;
UNION
SELECT ProductInfo.SKU, Attributes.AttribName, Attributes.AttribValue
FROM (ProductVariationGroups INNER JOIN ProductInfo ON ProductVariationGroups.PK_ProductVariationGroups_ID = ProductInfo.FK_ProductVariationGroups_ID) INNER JOIN (Attributes INNER JOIN ProductVariationAttributes ON Attributes.PK_Attribute_ID = ProductVariationAttributes.FK_Attribute_ID) ON ProductVariationGroups.PK_ProductVariationGroups_ID = ProductVariationAttributes.FK_ProductVariation_ID;
The problem with the query is that if an attribute has been applied to the variation group such as AttribNameame = "Gift Wrap Available" AttribValue = "Yes" and then an attribute has been applied to the product such as AttribNameame = "Gift Wrap Available" AttribValue = "No", the query shows both attributes where as the product attribute should take precedence, and therefore the query should only show AttribNameame = "Gift Wrap Available" AttribValue = "No".
I think it has something to do with the Attributes,ProductAttributes and ProductVariationAttributes all needing a column for AttribType and that way the query can tell that both values belong to the same type and only use the value from the ProductAttributes instead of ProductVariationAttributes.
I hope this make sense and have written this in very broad terms to get the basic logic across and am willing to expand on it if necessary. Also I have included screenshots of the basic table relationships and queries used and a sample database.
Regards,
Dylan