Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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:

order_id int(11) AI PK customer_id int(11) order_date datetime ship_amount decimal(10,2) tax_amount decimal(10,2) ship_date datetime ship_address_id int(11) card_type varchar(50) card_number char(16) card_expires char(7) billing_address_id int(11)

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;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote