title: select attribute mysql
body: <p>I have there mysql table:</p>
  
  <pre><code>**product (id,name)**
  1  Samsung
  2  Toshiba
  3  Sony
  
  **attribute (id,name,parentid)**
  1 Size 0
  2 19" 1
  3 17" 1
  4 15" 1
  5 Color 0
  6 White 5
  7 Black 5
  8 Price 0
  9 &lt;$100 8
  10 $100-$300 8
  11 &gt;$300 8
  
  **attribute2product (id,productid,attributeid)**
  1 1 2
  2 1 6
  3 2 2
  4 2 7
  5 3 3
  6 3 7
  7 1 9
  8 2 9
  9 3 10
  </code></pre>
  
  <p>And listed them like:</p>
  
  <pre><code>**Size**
  -- 19" (2)
  -- 17" (1)
  -- 15" (0)
  
  **Color**
  -- White (1)
  -- Black (2)
  
  **Price**
  -- &lt;$100 (1)
  -- $100-$300 (1)
  -- &gt;$300 (1)
  </code></pre>
  
  <p>Please help me the mysql query to list the attribute name and count the number product that this attribute have. EG: When select Size 19" (attribute.id 2)</p>
  
  <pre><code>**Size**
  -- 19"
  
  **Color**
  -- White (1)
  -- Black (1)
  
  **Price**
  -- &lt;$100 (1)
  -- $100-$300 (1)
  </code></pre>
  
  <p>This will query to attribute2product >> select the productid >> next query to select other attribute of that productid and display the attribute name, number of prod that attribute name now have... (Like Magento)</p>
  
  <p>Thanks,</p>