PLEASE WRITE AN ANSWER IN MYSQL WORKBENCH /* Write a SELECT statement that inclu
ID: 3727696 • Letter: P
Question
PLEASE WRITE AN ANSWER IN MYSQL WORKBENCH
/* Write a SELECT statement that includes: all customer_ids and last_names from the customers table, as well as the most recent order_date for each customer that has orders from the orders table. Only include one order_date per customer, this order_date should be the most recent order as shown in the order_date column. Name this column "Newest". Use a subquery in the SELECT clause of the SELECT statement to accomplish this. One customer does not have orders list that customer_id and last_name as well - so remember this will be a LEFT JOIN of the two tables. Also remember that there is a an operator called DISTINCT that you can use to list each customer only one time*/
orders table:
Table: orders
Columns:
Table: customers
Columns:
Explanation / Answer
SELECT C.customer_id, C.last_name, O.Newest FROM customers C LEFT JOIN (SELECT order_date as Newest FROM orders ORDER BY order_date DESC LIMIT 1) as O ON C.customer_id = O.customer_id;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.