title: MySQL sum up numbers in a relational database
body: <p>I'm making a web application to make customers order items for anything. For that I've made  a MySQL database which has the following tables:</p>
  <ul>
  <li><code>customers</code></li>
  <li><code>orders</code></li>
  <li><code>order-items</code></li>
  <li><code>products</code></li>
  </ul>
  <p>In the <code>customers</code> table is all the information about the person such as:</p>
  <ul>
  <li>The customer ID, for the primary key and auto increment (id)</li>
  <li>The first name (first_name)</li>
  <li>The last name (last_name)</li>
  <li>The email address (email_adress)</li>
  <li>Information about the customer (customer_info)</li>
  </ul>
  <p><strong>Example:</strong></p>
  <p><img src="https://i.stack.imgur.com/aazta.png" alt="enter image description here" /></p>
  <p>In the <code>orders</code> table is all the specific information about it such as:</p>
  <ul>
  <li>The order ID, for the primary key and auto increment (id)</li>
  <li>Which customer ordered it, linked with <code>id</code> field from the <code>customers</code> table (customer_id)</li>
  <li>Order information (order_info)</li>
  <li>The location where the order needs to go to (location)</li>
  <li>When the order was created (created)</li>
  </ul>
  <p><strong>Example:</strong></p>
  <p><img src="https://i.stack.imgur.com/aoH9y.png" alt="enter image description here" /></p>
  <p>In the <code>order-items</code> table are all the items which every customer ordered, this is being linked by the <code>order-id</code> from the previous table.</p>
  <ul>
  <li>The ID, for primary key and auto increment, not used for any relation (id)</li>
  <li>The order ID, used for which product is for which order. This is linked with the <code>id</code> field from the <code>orders</code> table (order_id)</li>
  <li>The product ID, this is used for what product they ordered, this is linked with the id field from the <code>products</code> table. (product_id)</li>
  <li>The amount of this product they ordered (quantity)</li>
  </ul>
  <p><strong>Example:</strong></p>
  <p><img src="https://i.stack.imgur.com/R1w0r.png" alt="enter image description here" /></p>
  <p>In the <code>products</code> table is all the information about the products:</p>
  <ul>
  <li>The ID, for primary key and auto incrementing, This is linked with the <code>product_id</code> field from the <code>order_items</code> table (id)</li>
  <li>The name of the product (name)</li>
  <li>The description of the product (description)</li>
  <li>The price of the product (price)</li>
  </ul>
  <p><strong>Example:</strong></p>
  <p><img src="https://i.stack.imgur.com/d9BI1.png" alt="enter image description here" /></p>
  <p><strong>The problem</strong></p>
  <p>Bob ordered <code>product_id</code> 2, times 3. Which is the sandwich with beef with the price of <code>2.50</code>, which we have to multiply by 3 because it has been ordered 3 times. Which is <code>7.50</code></p>
  <p>Bob also ordered <code>product_id</code> 3, times 5. Which is the sandwich with chicken with the price of <code>3.00</code>, which we have to multiply by 5 because it has been ordered 5 times. Which comes out on <code>15.00</code></p>
  <p>Now I need to sum these up. Which is <code>15.00 + 7.50 = 22.50</code></p>
  <p><strong>The question</strong></p>
  <p>How do I get the <code>product_id</code> linked with the actual price of the <code>product_id</code>? which I can then multiply by the quantity.</p>
  <p>And then sum up all those values with the same <code>order_id</code></p>
  <p>For the first order we get product 2 (Quantity 3) and product 3 (Quantity 5), which should add 2.50<em>3 + 3.00</em>5 = 22.50</p>