Mysql – Multiple product attribute inventory database design

database-designMySQL

I have a database to build based on inventory for my shop. This is the current data that I have put into tables. This is the package:

the package

This is the product attribute:

attributes

This is the table to produce

inventory list

The problem is, each product has different packages. The data shown is the product that has 2 packages, "color" and "power".

So the question is: how to do "color" and "power" as column on the database?
and what will happen if it has more than 2 packages?

I am using MySQL for this.

What I'm going to do is to track the quantity,

product-23 : white, 100 = 30qty  
product-23 : white, 50 = 30qty  
product-23 : black, 100 = 30qty  

What I have is 2 tables "package" and "values", includes already have tables like product that has product id.

So whenever one user is trying to purchase product-23 : white, 100, it will check the quantity on the database.

Here is the fiddle

Best Answer

You have basically created a basic Key Value Store. See here for more details on that. You will need to make use of the PIVOT command to get the result you need. Check here for that.