SQL Query to Find Most Recent Order Date for Each Customer

Write a SQL query to find the most recent order date for each customer in a given table. The table should have the following columns: customer_id, customer_name, order_date .

Problem

Given a table of data with customer information, write a SQL query to find the most recent order date for each customer.
Input:
Customer table with the following columns:
- customer_id
- customer_name
- order_date
Output:
Table with the following columns:
- customer_id
- customer_name
- most_recent_order_date

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT customer_id, customer_name, MAX(order_date) AS most_recent_order_date
FROM customer
GROUP BY customer_id, customer_name;

/*

The solution above is optimal because it uses the MAX function to find the most recent order date for each customer.

*/

A.I. Evaluation of the Solution

The solution above is optimal because it uses the MAX function to find the most recent order date for each customer.

Evaluated at: 2022-11-12 02:15:55