PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

You have a database that contains the tables shown in the exhibit. (Click the Exhibit button).

You need to create a query for a report. The query must meet the following requirements:
NOT use object delimiters.
Return the most recent orders first.
Use the first initial of the table as an alias.
Return the most recent order date for each customer.
Retrieve the last name of the person who placed the order.
Return the order date in a column named MostRecentOrderDate that appears as the last column in the report.
The solution must support the ANSI SQL-99 standard.
Which code segment should you use?

To answer, type the correct code in the answer area.

PrepAway - Latest Free Exam Questions & Answers

Answer: See the explanation

Explanation:
SELECT C.LastName, MAX(O.OrderDate) AS MostRecentOrderDate FROM Customers AS C INNER JOIN Orders AS O ON C.CustomerID =O.
CustomerID GROUP BY C.LastName ORDER BY MostRecentOrderDate DESC

2 Comments on “Which code segment should you use?

  1. overkill says:

    Solution with fixes

    Select c.LastName, MAX(o.OrderDate) as MostRecentOrderDate
    From Orders o
    Inner Join Customers c ON c.CustomerID = o.CustomerID
    Group By c.CustomerID, c.LastName
    Order by MostRecentOrderDate Desc




    3



    1

Leave a Reply