__STYLES__
Scenario: The client wants you to track information on his customers (first name, last name, email),
his employees (first name, last name, start date, position ), his products, and the
purchases customers make (which customer, when it was purchased, for how much money).
-- table: customers
-- cust id, first name, last name, email
-- table: employees
-- emp id first name, last name, start date, position
-- table: products
-- product id, product name
-- table: cust purchases
-- cust purchase id, cust id, product id, purchased at, amount_usd
I also added Nonnull constraints to the columns where that constraint matched the data context, and made the "email" column from the customers table Unique to help ensure data consistency and accuracy.
USE bubsbooties;
SELECT * FROM customers;
INSERT INTO customers VALUES
('1', 'Marlene', 'Calsbeek', 'abc@xyz.com'),
('2', 'Arlene', 'Ogle', 'xyz@abc.com'),
('3', 'Eldrige', 'Ogle', 'email@gov.com');
SELECT * FROM employees;
INSERT INTO employees VALUES
('1', 'Ted', 'Mosby', '2001-01-01', 'Architect'),
('2', 'Robin', 'Scherbatsky', '2002-02-02', 'Reporter'),
('3', 'Marshall', 'Erickson', '2003-03-03', 'Lawyer');
SELECT * FROM products;
INSERT INTO products VALUES
('1', 'chocolatefrogs', '2001-03-24'),
('2', 'fizzingwhizzbees', '2001-5-15'),
('3', 'pumpkinpasty', '2002-02-24');
SELECT * FROM customer_purchases;
INSERT INTO customer_purchases VALUES
('1', '1', '2', '1'),
('2', '3', '1', '3'),
('3', '2', '3', '2');
SELECT
cust_purch.customer_purchase_id,
customers.first_name,
customers.last_name,
products.product_id,
products.product_name
FROM customer_purchases cust_purch
JOIN customers ON cust_purch.customer_id = customers.customer_id
JOIN products ON products.product_id= cust_purch.product_id
WHERE cust_purch.customer_purchase_id = '1';