title: MySQL database to store product, color, size and stock
body: <p>I have an assignment for shopping cart dealing with shirt store, and was confusing with database design in storing shirt attributes such as color, size and stock for each item.</p>
  <p>Let's say to store below shirt to db:</p>
  <pre><code>Product name: Nike shirt  
  Available colors: black, white, blue 
  Size: M, L, XL 
  Stock: Black - M - 5 pc
         White - L - 10 pc
         Blue  - M - 2 pc
         Blue  - XL - 3 pc
         (and so on...)
  </code></pre>
  <p>Instead of storing above info iteratively in a table like so:</p>
  <pre><code>table shirt
    id    product       color    size   stock
  ---------------------------------------------
     1    Nike Shirt    black     M       5
     2    Nike Shirt    white     L       10
     3    Nike Shirt    blue      M       2
     4    Nike Shirt    blue      XL      3
    ....
  </code></pre>
  <p>What is the best way to design table to keep these attribute and product effectively?</p>
  <p>I know that could be JOIN multiple table together, but I need advise on these attributes on how to put separately with difference table and fetch the info when people goes to respective page and show them up how many stock are left for the specific size?</p>