Skip to content
Advertisement

Why are Duplicates not being filtered out

I am working on some practice interview Questions and am struggling with this:

You are working with a company that sells goods to customers, and they’d like to keep track of the unique items each customer has bought. The database is composed of two tables: Customers and Orders. The two table schemas are given below. We want to know what unique items were purchased by a specific customer, Wilbur, and when they were purchased. What is the correct query that returns the customer first name, item purchased, and purchase date with recent purchases first? Tables: https://imgur.com/a/D47R1KU

My answer so far is

However I am getting an incorrect message as its Printing wilbur,oranges,2019-06-10 and wilbur,oranges,2018-06-10 instead of just the one with the more recent date. Please see the picture for the two tables referenced by the question. Thanks!

Advertisement

Answer

Between the where clause and ORDER BY, try:

GROUP BY FirstName, Item

And to get the most recent date, select MAX(PurchaseDate).

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement