title: SQL creating and interacting with three tables
body: <p>So here is what I'm playing around with: Let's simulate an e-commerce site. We're going to need users, products, and orders.</p>
  <ul>
  <li>Users need a name and an email.</li>
  <li>Products need a name and a price</li>
  <li>Orders need a ref to product.</li>
  </ul>
  <p>All 3 need primary keys.</p>
  <hr />
  <p><em>Instructions</em></p>
  <ul>
  <li>Create 3 tables following the criteria in the summary. Add some data to fill up each table - at least 3 users, 3 products, 3 orders.</li>
  <li>Run queries against your data: Get all products for the first order; Get all orders; Get the total cost of an order ( sum the price of all products on an order ).</li>
  <li>Add a foreign key reference from orders to users and update the orders table to link a user to each order.</li>
  <li>Run further queries against your data: Get all orders for a user; Get how many orders each user has.</li>
  </ul>
  <p>Can somebody with a little time on their hands write out what this would look like. I would be forever grateful is someone could write this out so I could study it, get past this problem and see how this is done. Here's what I have so far:</p>
  <pre><code>   CREATE TABLE orders (
       order_id SERIAL PRIMARY KEY,
       stuff VARCHAR(150),
       product_id INTEGER REFERENCES products(product_id)
       );
      
    INSERT INTO users (name, email)
      VALUES
      ('Justin', 'Justinjgh@gmail.com'),
      ('Bill', 'Bill@gmail.com'),
      ('Rick', 'Rick@gmail.com');
    
    INSERT INTO products (name, price)
      VALUES
      ('Chair', 22),
      ('Turkey', 10),
      ('Lizard', 10000);
    
    INSERT INTO orders (stuff, product_id)
      VALUES
      ('Testthis', 1),
      ('Testthat', 2),
      ('Andtestthis', 3);
    
    SELECT * FROM products
      WHERE product_id = 1;
    
    SELECT * FROM orders;
  </code></pre>