title: Limit sum of rows in MySQL
body: <p>I want to limit the sum of <code>product_</code> in columns <code>p_description</code>, <code>p_reference = 1A00001</code> and only show rows that give us a total <code>p_quanity</code> &lt;= 21000.</p>
  
  <p>Here is the design of the product_table:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `product_table` (
    `p_id` int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
    `p_description` varchar(50) NOT NULL,
    `p_reference` varchar(25) NOT NULL,
    `p_location` varchar(25) NOT NULL,
    `p_quantity` int(11) NOT NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
  
  INSERT INTO `product_table` (`p_id`, `p_description`, `p_reference`, `p_location`, `p_quantity`) VALUES
  (1, 'Product_1', '1A00001', 'AP07', 7000),
  (2, 'Product_1', '1A00001', 'AF05', 6000),
  (3, 'Product_1', '1A00233', 'DS07', 7000),
  (4, 'Product_1', '1A00233', 'SD10', 5000),
  (5, 'Product_1', '1A00001', 'YB12', 7000),
  (6, 'Product_1', '1A00001', 'AN01', 7000),
  (7, 'Product_1', '1A00001', 'AP04', 7000),
  (8, 'Product_1', '1A00245', 'AP01', 7000),
  (9, 'Product_1', '1A00001', 'QD01', 7000),
  (10, 'Product_1', '1A00001', 'SC01', 7000);
  </code></pre>