2. Create a SQL query that shows the customer_id, customer last name, customer f
ID: 3607410 • Letter: 2
Question
2. Create a SQL query that shows the customer_id, customer last name, customer first name, customer street address, city and state, along with the order id, product name and list price.
All of the customer details come from the demo_customers table. You will have to join this table to the demo_orders table usingorder_id and then join the demo_orders table to the demo_products table using product_id.
3. Turn this SQL query into a view, like this:
CREATE VIEW customer_purchases_vw AS(
sql query goes here…
);
Explanation / Answer
Answer is as follows:
SQL query for given problem:
SELECT customer_id,last_name,first_name,street_address,city,state,order_id,product_name,list_price FROM(SELECT * FROM demo_customer FULL JOIN demo_orders ON demo_customer.order_id = demo_order.order_id ) FULL JOIN ( SELECT * FROM demo_order ON demo_products ON demo_order.product_id = demo_product.product_id);
View for obtained sql query:
CREATE VIEW customer_purchases_vw AS(
SELECT customer_id,last_name,first_name,street_address,city,state,order_id,product_name,list_price FROM(SELECT * FROM demo_customer FULL JOIN demo_orders ON demo_customer.order_id = demo_order.order_id ) FULL JOIN ( SELECT * FROM demo_order ON demo_products ON demo_order.product_id = demo_product.product_id)
);
if there is any query please ask in comments....
Updated :
CREATE VIEW customer_purchases_vw
AS
SELECT customer_id,last_name,first_name,street_address,city,state,order_id,product_name,list_price FROM(SELECT * FROM demo_customer FULL JOIN demo_orders ON demo_customer.order_id = demo_order.order_id ) FULL JOIN ( SELECT * FROM demo_order ON demo_products ON demo_order.product_id = demo_product.product_id);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.